Controlling a Raspberry Pi / Arduino Bot from the Internet Part 2 of 3

This is part two of a three part Series to explain how I control my BotTwosemi-Autonomous Robot from a webpage on the Internet.

InPart One, we talked about the Interaction and Communications between the end user device (laptop/tablet/phone), the Web Server presenting the control panel, and the socket service listening for commands on the Robot itself.

This series will allow you to operate your Robot like an RC Car via the Internet.

This is the mode described here, with code examples for each programming platform. As part of my learning process, I chose a very simple DIY approach, as opposed to a framework like node.js

We will take the incoming message, and repeat it viaI2Cto the Arduino that is managing the DC motors and wheel encoders.

Note:typically, there would be a validation step between receiving the command, and issuing it to the motor controllers.

You would want to ensure that the command made sense, but also ensure that it was not going to put the robot into danger. This would include proximity / obstacle detection, as well as "cliff detection". In more advanced robots, you may also haveenvironmental sensorsthat could ensure that the path chosen was safe to travel.

Ok... so... in my implementation, I rely heavily on theAdafruit Raspberry Pi python library forI2Ccommunications both for existing I2C sensors, as well as for communicating with my Arduino's. I fully admit to replicating an existing I2C sensor library, and then making it work with my motor controller Arduino.

Adafruit_I2C.pyprovides a number of methods for sending and receiving data via I2C, in 8bit bytes, 16bit integers, or character array (python list) form.

Please read the comments. This is a bare-bones implementation that takes a command string, and forwards it to The arduino via I2C for processing.

You will need to add your proximity and safety testing to this. As well, sending a string via I2C is not the most efficient use of the bus. I simply did this so that I had both options available on the Arduino.

A proper Data Register method will be shown in an upcoming article.

As you will see in the next segment of this series, I share the Command Interpreter / processor between the serial port and the I2C. Commands can be received via either.