Skip to content

14. Networking and communications

Group task

I did the group work with Michael, Jobin, Sahan and Yasir.

We used the Bluetooth Control Lamp app to communicate between different boards with a mobile phone over Bluetooth.


Pairing the phone with the Bluetooth module.

Complete network.

More details about the group assignment can be found in Jobin’s and Sahan’s pages.

Individual assignment

I used the board from my output week (referred now onward as board1), along with an older board from Electronics design week (referred now onward as board2) for this assignment. The master controller is the PC which is connected via USB with the board1. Board1 is providing a serial interface by using CDC class. The software is taken from LUFA. Details regarding the virtual serial interface can be found from week16 documentation. The implemented network is of daisy chain topology. It can be easily converted to a star topology by changing the embedded code.

Network of PC, board1 and board2.

Embedded Software

Board1

Board1 is the first node and is interfaced with the PC using virtual serial over the USB. Whenever it receives any valid data, it checks if it is for its own board ID or not. If it is for its own ID, then it handles it locally by calling handle_local, otherwise, it forwards the complete data packet to the next node by calling forward_data

                    if (data[2] >= BOARD1 && data[2] <= BOARD2)
                    {
                        switch (data[2])
                        {
                            case BOARD1:
                            {
                                handle_local(data[3]);
                            }
                            default:
                            {
                                forward_data(data[2], data[3]);
                            }

                        }
                    }

Below is the function for forwarding the data to the next node in the network.

int forward_data(uint8_t board_id, uint8_t incmng_data)
{
    uint8_t data[6];
    uint8_t i=0;
    data[0] = 128; data[1] = 164; data[5] = 128;

    data[2] = board_id;
    data[3] = incmng_data;
    data[4] = 0;

    for (i=0;i<6;i++)
    {
        put_char(&serial_port, serial_pin_out, data[i]);
    }

    return 0;
}

Board2

Board2 is the second node and is interfaced with Board1 over serial connection. As this is a daisy chained network, board2 should also forward and received data which is not meant for itself. However, as there are no more free pins available on the board2, right now the forward_data function is empty.

        if ((buffer[0] == 128) && (buffer[1] == 164) && (buffer[5] == 128))
        {
            if (buffer[2] >= BOARD1 && buffer[2] <= BOARD2)
            {
                switch (buffer[2])
                {
                    case BOARD2:
                    {
                        handle_local(buffer[3]);
                    }
                    default:
                    {
                        forward_data(buffer[2], buffer[3]);
                    }

                }
            }
        }

Demo

Below is a short video showing a sample gui with two buttons. At every button press, the corresponding board LED is toggled. Board1 has a green LED and board2 has a white LED. Both boards have a green LED showing the power status.

Afterthoughts

Given my background in electronics, this assignment was not fiendishly difficult. In case I ever have to use a networking bus, I would however stick to standard buses like I2C or 1-Wire instead of creating my own protocol.

Files