Skip to content

14. Networking and communications

  • Group assignment: Send a message between two projects (assignments made by different students)

  • Individual assignment: design, build, and connect wired or wireless node(s) with network or bus addresses

Designing the wired networking boards

These are the circuits that I redraw. All the necessaries components are in the fab library.

Eagle

Bridge board

Component SMD Code Quantity
ATtiny45 or ATtiny85 TINY45 or TINY85 1
10kΩ resistor 1002 1
1x6 pin header male NONE 1
2x2 pin header male NONE 1
1uF capacitor NONE 1
2x3 pin header NONE 1

This is the bridge schematic.

This image of the board with the components places that will help during the soldering.

Node board

Component SMD Code Quantity
ATtiny45 or ATtiny85 TINY45 or TINY85 1
10kΩ resistor 1002 1
2x2 pin header male NONE 1
1uF capacitor NONE 1
2x3 pin header NONE 1

This is the node schematic.

This image of the board with the components places that will help during the soldering.

Files of Eagle

These are the images for routing the boards using MODS, I also added the gerber files for generating the toolpath using flatcam.

These images have 1000 dpi. This quality is to avoid errors during the toolpath.

Both the boards have + and - on the board to avoid bad connections.

Bridge board

Node board

This files includes the schematics, boards gerbers and CAM jobs.

If you want to improves these boards these files will helps you.

Routing the networking boards

This time I wanted to try to import in flatcam a PNG file as a gerber in order to save the project and modify easily, for example, the end mill diameter.

I found that you can import as a geometry or gerber. The difference between them is where the end mill going to pass. In the geometry the end mill pass on shape and is the toolpath itself, in other hand, if you import as a gerber the end mill will pass around the closed of the shape and the toolpath quantity depends of you.

Another thing about the software is that knowing the exactly dpi value of the images this it will imported in the right scale, otherwise, it increase the size or decrease its size.

Here I downloaded the hello boards, the only thing is that flatcam recognizes the black areas as the copper that you do not want to remove, so we have to invert somehow to have the right images to import.

GIMP

  1. First find the PNG images that you want to route. This can be anything you want, even an custom image for decoration of your board.

  2. Download the image.

  3. Is very important create a folder with the name of the project that you are doing, all this to keep the order.

  4. Then you have to edit the image using a software of your preference, in this case is GIMP.

  1. This edition I did in a laptop with Windows OS with GIMP 2.10 RC1.

  2. Then go to Color>Invert.

  3. This is the image before inverting.

  4. This image is the inverted image.

  1. Then go to File>Export as.

  2. Select the name and the output format, in this case PNG.

  3. Then the software will ask you the compression level, so we do not need any compression of the image.

  4. Finally go to File>Save for saving your original edited image in GIMP format XCF.

  1. Select the name and where you want to save.

  2. Press Save.

Files of GIMP

Flatcam V 8.914

  1. To import the PNG you have to go to File>Import>ImageAsObject.

  2. Here we can see that you can import as a Gerber or as a Geometry. In this case is as a Gerber.

  3. Set the DPI value in 1000 as a Standard, only if you do not know its value. Then press import.

  4. Here we can see the imported image without previous invertion of the color in GIMP.

  1. Here we can see the same image but inverted and it have the same size. To move one of the you have to select one of them and rigth click and select move.

  2. The software will ask you a reference point and then the new place point of the selected reference.

  3. Go to Tool>Measurement for measuring the known distance to calculate the scale.

  4. The measuring tool it will ask you for two points, so before that we have to adjust the grid size small as possible to get more precision during the measuring.

  1. This is may reference distance, and I compared with the footprint distance provided in the Datasheet of the component.

  2. Set the scale factor and press scale. These two tools you will use until you hit the right distance.

  3. Here I show the Object transform tools and where is placed the scale tool.

  4. After got it the correct distance we can go to the next step.

  1. First of all we have to place the board in the positive quadrant of the Cartesian plane.

  2. Is always helpful to give to the board a clearance in order to get a clean cut.

  3. The intersection of this two red lines is the origin.

  4. Here we can see the parameters that I used to create the toolpath.

  1. In this step we can see the parameters that I used to obtain the toolpath from the geometry.

  2. Flatcam allows you many post-processes. The one that is interesting to know about is the post process for the Roland MDX-20.

  3. Finally save the generate code for send to the machine later.

  4. Select the location an the name and press save.

  1. The next code to generate for is the cutting box, here I show what parameters I used.

  2. Then we have to create the toolpath. These are the parameters that I used.

  3. Finally save the code in the location of your election.

  4. This is an important thing to do, save the Flatcam project.

  1. Select the location for your project.

  2. Press save to save your project.

  3. Select the name.

Files of Flatcam

The file named hello.bus.45.bridge.traces.3.png_iso_cnc.nc used a 1/64” end mill and is for routing the traces of the board.

The file named hello.bus.45.bridge.traces.3.png_bbox_cnc.nc used a 1/32” end mill and is for cutting the board.

Every flatcam output with the word iso is for routing the traces of the board and with the word bbox is for cutting the board

Faced problems and solutions during the routing the networking boards

Problems

  1. The PNG file was imported with the the non copper areas as a copper areas.

  2. The scale of the gerber was wrong.

Solutions

  1. The solution was to invert the image using GIMP.

  2. The solution was to measuring a known distance and scale manualy.

Soldering and programming the networking boards

AVR C

Codes I used to program the boards

I used the example code given by Neil.

//
//
// hello.bus.45.c
//
// 9600 baud serial bus hello-world
//
// Neil Gershenfeld
// 11/24/10
//
// (c) Massachusetts Institute of Technology 2010
// Permission granted for experimental and personal use;
// license for commercial sale available from MIT.
//

#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <string.h>

#define output(directions,pin) (directions |= pin) // set port direction for output
#define input(directions,pin) (directions &= (~pin)) // set port direction for input
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define bit_delay_time 100 // bit delay for 9600 with overhead
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
#define led_delay() _delay_ms(100) // LED flash delay

#define led_port PORTB
#define led_direction DDRB
#define led_pin (1 << PB0)

#define serial_port PORTB
#define serial_direction DDRB
#define serial_pins PINB
#define serial_pin_in (1 << PB3)
#define serial_pin_out (1 << PB4)

#define node_id '0'

void get_char(volatile unsigned char *pins, unsigned char pin, char *rxbyte) {
   //
   // read character into rxbyte on pins pin
   //    assumes line driver (inverts bits)
   //
   *rxbyte = 0;
   while (pin_test(*pins,pin))
      //
      // wait for start bit
      //
      ;
   //
   // delay to middle of first data bit
   //
   half_bit_delay();
   bit_delay();
   //
   // unrolled loop to read data bits
   //
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 0);
   else
      *rxbyte |= (0 << 0);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 1);
   else
      *rxbyte |= (0 << 1);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 2);
   else
      *rxbyte |= (0 << 2);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 3);
   else
      *rxbyte |= (0 << 3);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 4);
   else
      *rxbyte |= (0 << 4);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 5);
   else
      *rxbyte |= (0 << 5);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 6);
   else
      *rxbyte |= (0 << 6);
   bit_delay();
   if pin_test(*pins,pin)
      *rxbyte |= (1 << 7);
   else
      *rxbyte |= (0 << 7);
   //
   // wait for stop bit
   //
   bit_delay();
   half_bit_delay();
   }

void put_char(volatile unsigned char *port, unsigned char pin, char txchar) {
   //
   // send character in txchar on port pin
   //    assumes line driver (inverts bits)
   //
   // start bit
   //
   clear(*port,pin);
   bit_delay();
   //
   // unrolled loop to write data bits
   //
   if bit_test(txchar,0)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,1)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,2)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,3)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,4)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,5)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,6)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,7)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   //
   // stop bit
   //
   set(*port,pin);
   bit_delay();
   //
   // char delay
   //
   bit_delay();
   }

void put_string(volatile unsigned char *port, unsigned char pin, PGM_P str) {
   //
   // send character in txchar on port pin
   //    assumes line driver (inverts bits)
   //
   static char chr;
   static int index;
   index = 0;
   do {
      chr = pgm_read_byte(&(str[index]));
      put_char(&serial_port, serial_pin_out, chr);
      ++index;
      } while (chr != 0);
   }

void flash() {
   //
   // LED flash delay
   //
   clear(led_port, led_pin);
   led_delay();
   set(led_port, led_pin);
   }

int main(void) {
   //
   // main
   //
   static char chr;
   //
   // set clock divider to /1
   //
   CLKPR = (1 << CLKPCE);
   CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
   //
   // initialize output pins
   //
   set(serial_port, serial_pin_out);
   input(serial_direction, serial_pin_out);
   set(led_port, led_pin);
   output(led_direction, led_pin);
   //
   // main loop
   //
   while (1) {
      get_char(&serial_pins, serial_pin_in, &chr);
      flash();
      if (chr == node_id) {
         output(serial_direction, serial_pin_out);
         static const char message[] PROGMEM = "node ";
         put_string(&serial_port, serial_pin_out, (PGM_P) message);
         put_char(&serial_port, serial_pin_out, chr);
         put_char(&serial_port, serial_pin_out, 10); // new line
         led_delay();
         flash();
         input(serial_direction, serial_pin_out);
         }
      }
   }

Steps for loading the program on the boards and test them.

  1. Open the directory where is located the source code (each board).

  2. Change the id value (each board).

This the value that we have to change for each board This change makes the board addressable one board to the next one

#define node_id '0'
  1. Load the program using (each board).This step requires the avrdude .
sudo program-usbtiny

This command is this Makefile:

PROJECT=hello.bus.45.id.0
SOURCES=$(PROJECT).c
MMCU=attiny45
F_CPU = 8000000

CFLAGS=-mmcu=$(MMCU) -Wall -Os -DF_CPU=$(F_CPU)

$(PROJECT).hex: $(PROJECT).out
    avr-objcopy -O ihex $(PROJECT).out $(PROJECT).c.hex;\
    avr-size --mcu=$(MMCU) --format=avr $(PROJECT).out

$(PROJECT).out: $(SOURCES)
    avr-gcc $(CFLAGS) -I./ -o $(PROJECT).out $(SOURCES)

program-bsd: $(PROJECT).hex
    avrdude -p t45 -c bsd -U flash:w:$(PROJECT).c.hex

program-dasa: $(PROJECT).hex
    avrdude -p t45 -P /dev/ttyUSB0 -c dasa -U flash:w:$(PROJECT).c.hex

program-avrisp2: $(PROJECT).hex
    avrdude -p t45 -P usb -c avrisp2 -U flash:w:$(PROJECT).c.hex

program-usbtiny: $(PROJECT).hex
    avrdude -p t45 -P usb -c usbtiny -U flash:w:$(PROJECT).c.hex

program-dragon: $(PROJECT).hex
    avrdude -p t45 -P usb -c dragon_isp -U flash:w:$(PROJECT).c.hex

program-ice: $(PROJECT).hex
    avrdude -p t45 -P usb -c atmelice_isp -U flash:w:$(PROJECT).c.hex
  1. Connect all the hardware together.

  2. Open in terminal the location of the file term.py.

  3. Execute the python file called term.py. This step requires pip, pyserial and tkinter.

sudo python term.py /dev/ttyUSB0 9600

to know the FTDI port type first /dev/ttyU and press tab

The wired networking boards in action

Files source code wired networking boards

All the Souce and HEX files

Designing the wireless networking board

HC-06 Datasheet

HC-06 Wireless Serial 4 Pin Bluetooth RF Transceiver Module RS232 TTL, It Allows your device to both send or receive the TTL data via Bluetooth technology without connecting a serial cable to your computer. Works with any USB Bluetooth adaptersFEATURESDefault Baud Rate: 9600, 8, 1, n.Built in antennaOperating voltage: 3.3VInput voltage: 3.3~6V

Feature

Wireless transceiver
  • Sensitivity (Bit error rate) can reach -80dBm.
  • The change range of output’s power:-4 - +6dBm.
Function description (perfect Bluetooth solution)
  • Has an EDR module; and the change range of modulation depth: 2Mbps - 3Mbps.
  • Has a build-in 2.4GHz antenna; user needn’t test antenna.
  • Has the external 8Mbit FLASH
  • Can work at the low voltage (3.1V~4.2V). The current in pairing is in the range of 30~40mA. The current in communication is 8mA.
  • Standard HCI Port (UART or USB)
  • USB Protocol : Full Speed USB1.1, Compliant With 2.0
  • This module can be used in the SMD.
  • It’s made through RoHS process.
  • The board PIN is half hole size.
  • Has a 2.4GHz digital wireless transceiver.
  • Bases at CSR BC04 Bluetooth technology.
  • Has the function of adaptive frequency hopping.
  • Small (27mm×13mm×2mm)
  • Peripherals circuit is simple.
  • It’s at the Bluetooth class 2 power level.
  • Storage temperature range: -40 °C - 85°C,work temperature range: -25 °C - +75°C
  • Any wave inter Interference: 2.4MHz,the power of emitting: 3 dBm.
  • Bit error rate: 0. Only the signal decays at the transmission link, bit error may be produced. For example, when RS232 or TTL is being processed, some signals may decay.
Low power consumption
Has high-performance wireless transceiver system
Low Cost

Designing in Eagle

Files of Eagle wireless networking board

All the Eagle files for wireless networking board

Programming the wireless networking boards

The reference I took from Instructables

Arduino C++

#include <SoftwareSerial.h>

#define RxD 1
#define TxD 2

#define DEBUG_ENABLED  1

SoftwareSerial blueToothSerial(RxD,TxD);

int led_matrix = 3;

void setupBlueToothConnection(){

  blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=HC-05\r\n"); //set the bluetooth name as "HC-05"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here

  delay(2000); // This delay is required.
  //blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  blueToothSerial.print("bluetooth connected!\n");

  delay(2000); // This delay is required.
  blueToothSerial.flush();

}


void setup(){

  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);

  setupBlueToothConnection();

  pinMode(led_matrix,OUTPUT);
  digitalWrite(led_matrix,HIGH);

}

void loop(){

  char recived_char;
  char last_recived_char;

  while(1){

    //check if there's any data sent from the remote bluetooth shield
    if(blueToothSerial.available()){

      recived_char; = blueToothSerial.read();

      if( recived_char == '1' ){

        digitalWrite(led_matrix,HIGH);
        last_recived_char = recived_char;

      }
      else if( recived_char == '0' ){

          digitalWrite(led_matrix,LOW);
          last_recived_char = recived_char;

      }

    }

  }

}

The Bluetooth board in action

Files of Arduino C++ source code for the wireless networking board

All the Eagle files for wireless networking board

Faced problems and solutions during the soldering and programming the networking boards

Problems

  1. The problem was that the selected pin for communication does not work because some configuration issues on the arduino IDE related to the working frequency.

Solutions

  1. When the communication is not performed properly I found that changing the work frequency and try to program again the board until the communication works.

What I learned this week?