In my last blog entry, I created a new graphical interface in Scratch for transmitting data to the microcontroller on the robot. Tonight I verified that the Scratch program is able to communicate via screen flashes with the Arduino test bed. In the above picture, the new action mode is shown in the Scratch code listing at left, and appears on the Arduino serial monitor on right. Mission accomplished.
The action mode value of “192” signals the microcontroller that it is to go to the light track procedure. Why ‘192?’ Well, because I’m sending the number of waypoints and the action mode in the same byte, and the first three bits are for the number of waypoints (ie, 0 to 7) and the upper three bits are for encoding the action mode. Hence action mode values must be combinations of 32, 64, and 128. The restriction wasn’t a problem at first but now I have nine action modes and I’m thinking I need to revise the protocol for the sake of future expansion.
Can you explain how to access the Scratch’s serial port ??
I don’t use Scratch’s serial port. Instead, I communicate between Scratch and my robot by having Scratch flash two squares (data and clock) on the screen which are then read by photocells on the robot and translated into commands. However, there appear to be videos on Youtube which describe how to communicate between Scratch and the Arduino over the serial port.