Assignment 14: Networking and Communications

Group assignment:
- Send a message between two projects
Individual assignment:
- Design and build a wired &/or wireless network connecting at least two processors

Group assignment
I did the documentation for the Networking and Communications group work. More about the group work is in the Networking and Communications.

Networking and communicating
I need 4 stepper motors for my final project to run peristaltic pumps, so I wanted to make a check all the necessary code and connections to make multiple stepper motors to work. I used my main board from the week Input devices, which works as the brains of the whole operation and commands controller board for the RepRap stepper driver modules from the week Output devices. The stepper driver modules are used to actually move the stepper motors. Main board is the board, that I'm using in my final project to control the whole system. Controller board for RepRap stepper driver modules is a board, which is used to control RepRap stepper driver modules. Both of the boards have ATmega328P microcontroller and I chose to use Arduino IDE to write the code to do the work. I wanted to make a simple code that sends the id (main board id = 8, motor controller id = 9) of the microcontroller, id of the motor and the amount of steps.



In the Neil's lecture on networking and communications, he drew a sketch how to add more boards on simple serial system. Host Tx pin is connected to Rx pin of all of the nodes and then Tx pin of all of the nodes is connected to host Rx pin. The communication between host and each node is controlled with an individual id. Every time there is no communication between host and node, the Tx pin is pulled high to stop any communication. In my case, I added id's for both of my boards.


Rx-Tx hub can be used to make this kind of communication to take place. Jari produced this kind of board during networking and communications week and I produced one for my final project debugging based on his designs.


I wanted to send all the information in a single package as a string. I used strtok and atoi to cut the string in three different values and saved them in the id, motor and steps. With this kind of system you can easily add several different boards to the serial and only vary their id and the boards know, which board has to do the command.


This way, I could handle the message in a correct microcontroller and run only one motor.


I wrote a simple code in c to check that strtok and atoi worked for my case and when I saw that the result was what I wanted, I moved to Arduino IDE. Strtok is used to split string into tokens (sequences of characters separated by delimiters), which are divided with delimiters. I used comma as a delimiter in my case. The first character in the string is the starting point for the scan for tokens. In the rest of the calls, function expects a null pointer and uses the position after the last token as the position for scanning. ( 2018)

Atoi is then used to convert strings that hold the values for the motor operation to integers ( 2018). Both the strings and integers are printed to see, if the code works as intended. In Ubuntu, I used
> gcc testi.c -o str
command to compile the code and then to run it I used
> ./str


Running the stepper motors
Because I was not sure if I needed the ENABLE pin powered in the StepStick A4988 stepper motor driver carrier, I wanted to make connections on a bread board. It took quite a lot of wiring to make all the connections, but finally I was done and used the code from the output week to run one stepper motor with the power supply limiting the voltage to 9 V and current to 0.7 A. At first, I realized that my motors did not get powered and I started to measure my connections and saw that the power and ground rails didn't go all the way throug the bread board and I had to change the connections and to put them all closer to each other.

When I was done with that problem and put the power supply back on, I Immediately saw that the current hit the limit and all of the stepper motors were rotating. The intended one worked correctly, but none of the others were supposed to move, but they rotated slowly. Then I understood what the ENABLE pin was for and found a good explanation for that. When ENABLE pin is pulled low the board is enbled and the motor energised. When set high the board is disabled and the motor is de-energised. Therefore, I connected one pin for each of the ENABLE pins added code to set them HIGH and run the test again and saw that other motors didn't move any more and the power consumption was normal. Then I switched to networking code and it run as intended. It was surprising to see that the code worked without any changes to it, but of course I had tested it and fixed the code at that point. The final connections were quite a mess, but saved me from making two new boards for ENABLE pins. Now I can finally move to make the final design of the stepper motor driver carrier board and the motor controller board.


Video of the rotating motors is shown below.

Reflection on this weeks assignment
This weeks assignment got me further in the final project and especially in the controlling of the motors and got me towards the final version of the stepper motor controller boards. There was plenty of learning and I understand a lot more about the stepper motors and their operation in multiple units. The networking between the boards with Arduino IDE was quite similar to interfaces week, which made it a lot easier.

The files used in the assignment are shared below:
Brains.ino Arduino IDE file for the main board of my final project.
MotorRotatingFinal.ino Arduino IDE file for the stepper motor controller board
testi.c Simple test code for strtok and atoi