go back

Networking

This week's assignment was to make a FabMade board talk to another node (in my case that node was a pc). Since I want my Final project to be wireless, I decided to make it talk to my pc using bluetooth.
The reason I don't use I²c or any other kind of protocol is simply that I already did that in the output devices assignment, where I put together two 8x8 led matricies that talk to the board via I²c. Also other protocols are explained in our group assignment
Anyhow, I will still explain what I²c is and how it works:
Basicallym it is a bidirectional databus that only needs two pins to work and to be able to talk to a whole array of other microcontrollers. The pins used are SCL (Serial Clock Line) and SDA (Serial Data Line). SCL sets the clock, while SDA transmitts the data. Devices are classified as Masters or slaves, and can send data to one another. Every slave has it's own adress and can therefore be talked to by the master even though there are other slaves on the same line.
To get that functionality, I used the adafruit bluefruit ez-link bluetooth serial adapter. It basically works over FTDI, so I designed the board such that I can just plug the adaptor into it.
Setting the adaptor is also very easy, you just have to provide it 3 - 16V of power and press the pair button on it. Then you go into your pc's bluetooth settings and search for new devices, the ezlink will then show up and when you click on it, it will set up everything for you and create a new COM port which you can connect to.

And that's it! now you can just connect set the COM-port it created in the arduino software (or any other program) and program your board or talk to it via serial communication.

Troubleshooting


When the module doesn't work i.e. doesn't turn on, cannot upload to it you cave to check three things on your setup.
The first and most obvious thing is power: If you are trying to power your module through the board you made, it's probably not going to work reliably. Try using a bench power supply and see if that helps.
Then there is actual communication, make sure you have connected TX to RX and vice versa. I made the mistake of connecting TX to TX and RX to RX and it took me quite a while to figure that one out.
Also there has to be a 1uF capacitor on the RST line of your board, to make it communicate correctly (otherwise the programmer out of sync error will occur). Problem is though that it has to be a polarized cap to work correctly, so make sure you have one of those handy.


Now for the actual assignment, I just wrote a very basic arduino sketch that actuates a servo motor, based on serial communication. When "open" is sent via the serial monitor, the servo turns 180° in one direction and holds that position. When "close" is sent the servo goes back to it's original position.
This is very basic, but it's also the exact functionality I need to have for my final project.
 #include <servo.h>
Servo servo;
int pos = 0;
String incomingByte = ""; 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
servo.attach(A5);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.readString();
                if(incomingByte.indexOf("open") > -1){
                  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
                 // in steps of 1 degree
                 servo.write(pos);              // tell servo to go to position in variable 'pos'
                 delay(1);                       // waits 15ms for the servo to reach the position
                 }
                }else if(incomingByte.indexOf("close") > -1){
                   for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
                    servo.write(pos);              // tell servo to go to position in variable 'pos'
                    delay(1);                       // waits 15ms for the servo to reach the position
                   }
                }
        }
}
               


Group Assignment

Here you can find this week's group assignment.

download the code