Week 12 - Networking and Communications

The assignment this week was to design and build a netowrk connecting at least two processors. As I want to make a lot of capacitance touch pads for my final project, I wanted to connect a few capacitance circuit boards together via serial bus. I would need each circuit board to send a signal identifying itself to the motherboard and then the motherboard would read the signal and print out the corresponding message. To do this, I would need to program in C and program each circuit board to send a signal only when the voltage difference was greater than 10,000 and to send a character identifying itself. Then, I would need to modify the python to read the identifications by circuit boards and print a result.


In preparation for this week, I had made a lot of txrx boards last week and programmed them to make sure there were no hardware issues. I detected a few, but most could be solved with simple soldering. One problem I encountered was that the 2x3 header and 2x2 headers were too close together. This was never a problem before since I only used the 2x3 header to program and the 2x2 header to connect to copper plates, so I never needed both headers simultaneously. However, with communications, I needed to use the 2x3 header to connect the boards and the 2x2 headers to connect to the copper plates. When I tried putting them both on, this happened.

To first solve this issue, I used a socket housing and soldered on wires. The other option was to use female crimp contact and female crimp housing. Here are my connectors made using socket housing.

I then realized that the tx and rx pins were on the opposing side and that this makeshift connectors would not work. Instead, I made a even more makeshift connector - using 2 jumper cables.

After all this, I figured I was done with the hardware for this week!

C Programming

I began my focus modifying the hello.txrx.45.c file and Shivaei's led.txrx.44.delta.ss.c. Hello.txrx.45.c had the code to read tx and rx input from the copper pads, and led.txrx.44.delta.ss.c defined the difference between tx and rx and had an if statement that only printed values when the difference between tx and rx were above a certain value. Both were pieces of the code that I needed, so I thought it would be a simple adjustment. As always, I underestimated the complexity of the editing. I first decided to edit the led.txrx.44.delta.ss.c, only to realize that it was not as simple as just changing the pins in the definition to convert a program from Attiny44 to Attiny45. I also had to edit the MUX of the new pin, which involved me finally reading through the Attiny datasheets and redefining other variables. This then became very complicated and I began to encounter a lot of errors with even converting the C file into a hex file. I then decided to edit the hello.txrx.45.c file instead and adding in an if statement. This appeared to program fine, but after troubleshooting, I realized that it wasn't sending any serial. To detect serial, I downloaded Arduino and used the serial monitor. Without the if statement though, there was serial. I couldn't figure out exactly why the if statement was stopping the serial from being transmitted. After speaking with Rob, I realized that I had to change how I defined diff. After this, serial was being sent!

Next was editing the program so that the circuit boards would communicate amongst each other. To do this, I had to define serial_pin_out as PB2. This was because PB2 was acting as the TX for serial communication, while PB4 was acting as TX for capacitance. After defining this, I was receiving serial from the first circuit board, but not the second one. I learnt that I had to clear serial_direction and serial_pin_out. Initially, I cleared in the definition section and once again, only the first circuitboard in the bus was communicating properly. My mistake was that I had to clear within the while function, otherwise serial_direction and serial_pin_out would never clear again.

Here is the final C file.

Python Programming

I edited hello.txrx.45.py to create difference canvases based on signal sent. My initial thought was that I could program the first circuitboard via C to send "1" and then I could make an if statement in python so that "byte1 == 1". However, with help of Rob, I learnt that Neil's program is such that numbers 1,2,3 and 4 are sent initially, and then after data is sent. I did not need this feature though so I deleted that from my python. Instead, I defined a variable x that would read the serial coming in. However, python would still not print a canvas. To troubleshoot, I printed x on terminal and the number 49 was coming up. This is when I realized that python converted the number sent to ASCII. Thus, the number 1 was actually read as 49 in python. Subsequently, I changed the if statements to match the ASCII number and voila!

Here is the final python file.

Working Product!

Thank you Rob, Kevin, Olga, Yuval, and Dixon for all of your your help!