Study archive - Week 15

Networking and communications

The task of the week was to design and build a wired and/or wireless network connecting at least two processors.

I have designed and built a wired network connecting three processors ATtiny45 following the example and instructions from the lecture. Each board has a led. At start all leds are off. One of the board is called bridge and is connected to PC via FTDI cable thus it is able to receive serial input from keyboard and show it also on terminal. When 0,1 or 2 is typed the terminal will show the message with node_id (i.e., node 0, node 1, or node2) and the correspondng led will be on. When these characters are typed also all the leds will flash once marking that they receive the signal.

Design and fabrication of the nodes

All three nodes have an ATtiny45 microcontroller. The boards are designed in Eagle based on the class example (see lecture topics Serial > asynchronous).

For the bridge board, I have added also a second led to indicate power. The 2x3 pin header is used for programming the microcontroller. The 2x2 header is used to connect the databus (DB) pins RX and TX to the microcontroller and to connect power and GND. The led pin is PB0.

Bridge board: Eagle schematics and board; png files for milling traces

The blue led added for litting when the network is powered up did not work actually during execution. However, this did not affect the networking itself so I will correct this problem later by replacing the led.

Node1 and node2 boards: Eagle schematics and board; png files for milling traces

Similar schematic and board layout are for node 2, but the led was red (see the source files at the end of the page).

Fabmodules for milling

The traces and outline png files created in Gimp are then used in Fabmodules (fabmodules.org) to generate the toolpaths for the Roland milling machine SRM-20. The result of this process are the rml files that are read by the Roland machine. At the fabmodules I have used for traces cut depth 0.1 (but sometimes it was needed to adjust to 0.2 or 0.15 because the wood support in the machine is not completely flat) and the tool diameter 0.3. For the outline the stock thickness was set to 1.75 and the cutdepth 0.5.

After milling, the boards were stuffed using pick and place and reflow oven.

Two nodes ready soldered in the reflow oven.

All three boards are ready to be programmed.

Then I prepared the databus cable with 4 wires for Rx, Tx, power and GND.

Programming

I have written the C code based on the Neil's code (hello.bus.45.c). For this I have used Atmel Studio and the GCC compiler to create the hex file. I have adapted slightly the code mainly:

  • to define the clock frequency for the microcontroller F_CPU 8000000
  • to make the led stay lit instead of flashing once when the corresponding node is called

The clock frequency is defined before the util/delay.h library:


                    #include <avr/io.h>
                    #define F_CPU 8000000UL 
                    #include <util/delay.h>
                    #include <avr/pgmspace.h>
                    #include <string.h>
                    

The code in the main loop is as follows: (this code applies to all three nodes; each node is identified in the code by the node_id variable)


                    while (1) {
                        get_char(&serial_pins, serial_pin_in, &chr);
                        flash();  ///the led flashes
                        if (chr == node_id) {
                            led_delay();
                            //put led on
                            clear(led_port,led_pin);
                            //write on the terminal the 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); // 10 for new line
                            input(serial_direction, serial_pin_out);  
                    }
                    

The code is compiled and then built a solution, resulting the hex file. The hex file is written in the flash memory of the microcontroller using AVRDUDE program and the usbtiny programmer. For this step, I have used command line (cmd.exe) as follows. In the same directory with AVRDUDE exe I have copied all three hex files and then I used the writting command:

avrdude -p t45 -P usb -c usbtiny -U flash:w:bridge_v2.hex for the bridge node (node 0 in the network).

avrdude -p t45 -P usb -c usbtiny -U flash:w:node1_v2.hex for the node 1.

avrdude -p t45 -P usb -c usbtiny -U flash:w:node2_v2.hex for the node 2.

The wiring of the boards for programming is as follows.

During execution, the networking wires have to be connected to each node by keeping the same orientation (Gnd to Gnd, Vcc to Vcc, Rx to Rx and Tx to Tx on all three nodes).

The result

The pictures below shows the led being on when the node was called (see terminal). When node 0 is called the green led is on.

When led 2 is called the red led is on.

See also a short demo video of the network in action.

In the course of implementing this network, minor problems were encountered when executing the code: sometimes, on the terminal the text was not readable and I have tried with different bit delay value ranging from 97 to 110. When the text become readable, the led did not function properly. I have concluded with the recommended bit delay of 100 for baud rate of 9600 for the bridge board, and with 105 for the other two nodes. I have also changed the order of the commands in the main loop. Not sure if these changes make a significant impact, but with these changes the code works fine.

Another problem was that the alignment in the Tera term window was not at the left, but it had some kind of indentation after each character. This was solved by setting Terminal > New Line > Receive : LF.

Summary of the week

It was an useful exercise and I plan to develop this further after the summer holiday, with other networking methods (Xbee or other wireless/radio communication protocols) and microcontrollers (e.g., Attiny44A).

Summary of Tools used

Software

Eagle

Atmel Studio C

AVRDUDE

GIMP

Fabmodules (fabmodules.org)

Hardware

Roland Milling machine SRM-20

Soldering machines: pick and place and reflow oven; electronics workbench for manual soldering

Source files for download

Eagle files

C files and hex files

Contact Details

  • Personal website
  • Email: firstname.lastname@oulu.fi
  • Page navigation

  • Home
  • About me
  • Study archive
  • Final project