Browse over 10,000 Electronics Projects

An Open Source Motor Controller for everyone

An Open Source Motor Controller for everyone

Management via Serial communication

If we wish to command OMC21 by means of an Arduino board, it is convenient to use a software serial communication, by using a single digital line to connect to the CN1 connector’s RX line; in this way the hardware serial port will be free to communicate with the PC.

The sample sketch can be found in Listing 4, where it is shown how it is possible to build the control byte (byte2) by starting from the settings of the single bits for direction and braking. It will be the int mode = (modeM2<<3) + (modeM1<<2) + (dirM2<<1) + dirM1 a code line to rebuild the complete byte, by moving and adding the single bits. At a later stage we will use the four Serial.write commands to send the single bytes containing the start character and the three data bytes.

Listing4


listing4



Advertisement1


Management via I²C communication

If you want to control OMC21 by means of Arduino’s TWI port, you just have to connect the two lines (SDA and SCL) between them for both ports, and to connect the GNDs for both boards. Pull-UP resistors are not needed for the simple reason that they are already inside the microcontroller, both in Arduino Uno and in the ATmega32U4, and they are automatically enabled, once the Wire.begin() function is recalled.

The sketch to command OMC21, to be loaded in Arduino Uno, is found within Listing 5, that appears to be very similar to the previously described listings. There is however an important difference with the way of communication by means of serial port, concerning the peripherals’ addressing system. While in a serial communication the data exchange happens point by point, that is two say only two peripherals interact between them, in the I²C Bus up to 127 Slave peripherals may coexist, and they are all communicating with the only master unit. The master unit in this case is Arduino Uno (or the command logic), while the slave units are the OMC21 boards; the obvious advantage is that more controllers and thus more motors can be used, and they are all managed by a single Arduino board, by using a single TWi port.

We would like to remind you that, for all intents and purposes, in Arduino the TWI port uses the I²C protocol, that is a Philips proprietary one (since they created it).

Pages: 1 2 3 4 5 6 7 8 9 10 11

 


Top