Skip to content

14. Networking and communications

This week I worked on design, build, and connect wired or wireless node(s) with network or bus addresses. [Reference]

Group assignment

This week of group assignment, We try to send a message between two projects.. Click HERE to see more detail of the group assignment.


Individual assignment

For this week, I decided to use Blink4Terry which the PCB board designed and milled in week 7, Electronics design week.

Redesign

I think the traces of Blink4Terry are too thin, so I do some changes to the PCB design.

In the PCB design of Fusion 360, I can set the design rules via clicking the ‘DRC tick mark’.
And In the ‘Sizes’, set the minimum width bigger or equal to 15mil.
Then reconnect all the traces.

Then export and turn it to gcode via mods, send the gcode to the machine via EdytorNC.

Soldering

After milling and wiping off the copper around the USB connection part, is time to solder.

The components for the New version of Blink4Terry are the same as the previous version:

Components Type Quantity
ATSAMD11C Microcontrollers 1
1K Resistor 1001 Resistors 2
0 Ohms Resistor 000 Resistors 1
1uF Capacitor Capacitor 1
3.3V Regulator 662K Regulator 1
1.8~2.2V LED LED 1
Press Button Switch 1
2x2 Male Pin Header Connector Pin Header 1

After finding all the components for the board. Put the lead-free paste on the board.

Then put all the components on the board.

I’ve chosen to use the hot plate to solder my PCB board.

After cooking it well, I used a multimeter to test if there were any short-circuit.
For me, no short-circuit found, perfect!

Programming

Entering the programming part~

Install firmware

For installing the firmware, I did the same steps in Embedded programming week, click HERE to see.

Testing the board

For making sure the PCB board can function normally, I’ve used the code in week 9, Embedded programming week.

// Pin config
int button = 2;
int led =  4;

// values for morse code, https://morsecode.world/international/timing.html
int unit = 100;   // base time unit for morse code, smaller is faster
int dot = unit; // same as dit (.)
int dash = unit * 3;  // same as dah (-)
int intra_char_space = unit;  // the gap between dits and dahs within a character
int inter_char_space = unit * 3;  // the gap between the characters of a word
int word_space = unit * 7;  // the gap between two words

// status values of button
int pressed = 0;

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
}

// functions of breathing light

void breathing() {
  for (int i = 0; i < 255; i++) {
    analogWrite(led, i);
    delay(1);
  }
  for (int i = 255; i > 0; i--) {
    analogWrite(led, i);
    delay(1);
  }
}

// functions of morse code

// "_" is used for spaces in between words. Every char already ends with a inter_char_space of 3 time units.
void _() {
  delay(word_space - inter_char_space);
}

void s() {
  // ...
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(inter_char_space);
}

void o() {
  // ---
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(inter_char_space);
}

void loop() {
  pressed = digitalRead(button);
  if (pressed == LOW) {
    // if pressed = true
    // SOS ···---···
    s();
    o();
    s();
    _();
  } else {
    // if pressed = false
    breathing();
    }
  }

It works~ ^^

Then, I went further on making the communications part.

For making SAMD11 boards communicate together, I’ve lookup the Datasheet.

And found out that to make them communicate, I need to connect input board TX1 to output board RX1 and input board RX1 to output board TX1.

Input board

Then I programed the input and output board’s codes.

// Pin config
int button = 2;
int led =  4;

// values for morse code, https://morsecode.world/international/timing.html
int unit = 100;   // base time unit for morse code, smaller is faster
int dot = unit; // same as dit (.)
int dash = unit * 3;  // same as dah (-)
int intra_char_space = unit;  // the gap between dits and dahs within a character
int inter_char_space = unit * 3;  // the gap between the characters of a word
int word_space = unit * 7;  // the gap between two words

// status values of button
int pressed = 0;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600); // sets the data rate in bits per second (baud) for serial1 data tranmission (SAMD11C PA30-TX1 PA31-RX1)
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
}


// functions of morse code

// "_" is used for spaces in between words. Every char already ends with a inter_char_space of 3 time units.
void _() {
  delay(word_space - inter_char_space);
}

void s() {
  // ...
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(inter_char_space);
}

void o() {
  // ---
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(inter_char_space);
}

void loop() {  
  pressed = digitalRead(button);
  if (pressed == LOW) {
    // if pressed = true
    // SOS ···---···
    Serial1.println('1');
    s();
    o();
    s();
    _();
  } else  {
    // if pressed = false
    }
  }

Output board

// Pin config
int button = 2;
int led =  4;

// values for morse code, https://morsecode.world/international/timing.html
int unit = 100;   // base time unit for morse code, smaller is faster
int dot = unit; // same as dit (.)
int dash = unit * 3;  // same as dah (-)
int intra_char_space = unit;  // the gap between dits and dahs within a character
int inter_char_space = unit * 3;  // the gap between the characters of a word
int word_space = unit * 7;  // the gap between two words

// status values of button
int pressed = 0;

String readString;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600); // sets the data rate in bits per second (baud) for serial1 data tranmission (SAMD11C PA30-TX1 PA31-RX1)
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);
}


// functions of morse code

// "_" is used for spaces in between words. Every char already ends with a inter_char_space of 3 time units.
void _() {
  delay(word_space - inter_char_space);
}

void s() {
  // ...
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dot);
  analogWrite(led, 0);
  delay(inter_char_space);
}

void o() {
  // ---
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(intra_char_space);
  analogWrite(led, 255);
  delay(dash);
  analogWrite(led, 0);
  delay(inter_char_space);
}

void loop() {
  while (Serial1.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial1.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial1.println(readString);
    s();
    o();
    s();
    _();
    readString="";
  }
}

How it works?

In the code of input board:
If the button is pressed, do SOS morse code and send ‘1’ to Serial1;
If no, do nothing.

In the code of output board:
Receive value from Serial1;
If Serial1 sends a signal, do SOS morse code and reset the value received from Serial1.

Result

And here is the result:

Yay^^

Downloads

Blink4Terry (New) f3z design file - Google Drive

Blink4Terry (New) trace & outline png file - .zip


Last update: June 28, 2022