Communicating directly with the Arduino in the Ninja Block

Requirements

  • ssh tools (to access Ninja Block)
  • internet access on Ninja Block (for installing 'screen' only)

Access NinjaBlock

First you must ssh into your Ninja Block.

  ssh ubuntu@ninjablock.local

(default password is "temppwd")

Install 'screen'

By default, 'screen' is not installed on the ubuntu image currently released. You can check with:

ubuntu@ninjablock:~$ screen -v
-bash: screen: command not found

Ensure you are connected to the internet for this step and install it with:

ubuntu@ninjablock:~$ sudo apt-get install screen

ninjablock service

The client code which runs as the 'ninjablock' service, uses the serial device to talk to the arduino. We need to stop it so that we may connect to the serial device.

ubuntu@ninjablock:~$ sudo stop ninjablock

After testing you can restart it with:

ubuntu@ninjablock:~$ sudo start ninjablock

Connect to the arduino

Now you can use 'screen' to connect to the serial device (on the Raspberry Pi this is /dev/ttyAMA0).

ubuntu@ninjablock:~$ screen /dev/ttyO1 9600

Note: to exit the screen session, press [ctrl] + [a], then [k].

Listening to the arduino

Now you will be able to see directly the json that is sent from the arduino.

For example, every 30 seconds, LED device data (Nina's Eyes Device ID 1007, Status LED DID 999) is sent from the arduino:

{"DEVICE":[{"G":"0","V":0,"D":1007,"DA":"000000"}]}
{"DEVICE":[{"G":"0","V":0,"D":999,"DA":"00FF00"}]}

Humidity (DID 30) and Temperature (DID 31):

{"DEVICE":[{"G":"0202","V":0,"D":30,"DA":44}]}
{"DEVICE":[{"G":"0202","V":0,"D":31,"DA":23.20000}]}

RF devices (DID 11):

{"DEVICE":[{"G":"0","V":0,"D":11,"DA":"001011110001111101010110"}]}

Talking to the arduino

The 'screen' connection is bi-directional, so you can send commands to the arduino. For example, sending a carriage return (hit [Enter] in 'screen') will result in an error response from the arduino:

{"ERROR":[{"CODE":1}]}

If you copy the command to set Nina's Eye's, you can modify it in a text field, then paste it directly to 'screen'. For example, this will turn the eyes blue:

{"DEVICE":[{"G":"0","V":0,"D":1007,"DA":"0000FF"}]}

Pasting a received RF command (such as a socket remote control), will have the arduino transmit that command via rf. For example:

{"DEVICE":[{"G":"0","V":0,"D":11,"DA":"001011110001111101010110"}]}

 

Happy Hacking!


James Zaki
James Zaki

Author