Configurable news ticker through Bluetooth

In this tutorial we expand the configurable news ticker so that it can wirelessly be updated using the Dwengo bluetooth module. After this tutorial you will be able to make all your projects wirelessly. You can for example build a wireless robot by combining this tutorial together with the tutorial of the light eating robot.

Requirements

  1. A Dwengo board
  2. A Dwengo programmer
  3. Enclosed USB cable
  4. A Dwengo bluetooth module
  5. Dwengo breadboard (optional)

Connecting the bluetooth module

The easiest way to wirelessly communicate with the Dwengo board is by using theDwengo bluetooth module. This module uses the serial interface which makes the usage very easy. You start by connecting the bluetooth module on the Dwengo board. This bluetooth module has four pins: two for power (ground and 5 V) and two pins that are required for the serial communication (one for sending (TXD) and one for receiving (RXD) data). The pins are illustrated in the following picture:

bluetooth pins


The easiest way to plug the module into the Dwengo breadboard and connect four wires in such a way that the 5 V is connected with the + of the expansion connector, the GND is connected with the -, and RXD and TXD are connected respectively with C6 and C7. When you do this correctly, you will get the following circuit:

bluetooth connection


Finally it is important to remove the jumper JP1-4 from the Dwengo board before powering on the bluetooth module. Since the bluetooth module is connected to the same pins as the RS232 chip on the Dwengo board. If you don't remove the jumper it is possible that you damage the RS232.

Wireless communication

You start with loading the necessary libraries. The new library for you is the dwengoBluetooth.h library.

  1. #include <dwengoConfig.h>
  2. #include <dwengoBoard.h>
  3. #include <dwengoBluetooth.h>

We define two macros to make the code more readabe. The most important one is PREDEFINED_LENGTH which specifies the maximal number of characters of the news ticker.

  1. #define NULL 0
  2. #define PREDEFINED_LENGTH 64 // Maximum number of characters in string

Similar as in the tutorial of the configurable news ticker we add the prototypes of two functions.

  1. unsigned char newsticker(ram char *msg, unsigned char position);
  2. void str2ram(static char *dest, static char rom *src);

The first prototype is for the newsticker function that was also used in the [tutorial about the news ticker]
(/tutorials/lcd). The second function will make it possible to copy a string from the program memory to the data memory. Otherwise the initial message we show on the LCD display will not be accepted by the function newsticker because it only receives strings from the data memory.

In the main loop we first initialize the needed variables, set the initial message and initialize the Dwengo board and LCD display.

  1. void main(void) {
  2. unsigned char position = 0;
  3. char buffer[PREDEFINED_LENGTH+1];
  4. str2ram(buffer, "Initial message... "); // initial message
  5. initBoard();
  6. backlightOn();

Next we initialize the bluetooth module:

  1. initBluetooth();

The function initBluetooth() will make it possible to set the speed of the module to 9600 baud. After the initialization we start an infinite loop that will repeat the following steps:

  1. Send message to computer.
  2. Wait until the computer sends a message back. In the meantime show the message on the LCD of the Dwengo board.
  3. Read the message send from the computer.
  4. Reply send to the computer.
  1. while(TRUE) { // do this forever
  2.  
  3.  
  4. // send something
  5. putrsUSART((const far rom char *)"\nGive message\n\r");
  6.  
  7. // while no new data is available
  8. while(!bluetoothReady()) {
  9. // display message with news ticker effect
  10. setCursorLCD(0,0);
  11. position = newsticker(buffer, position);
  12. delay_ms(400);
  13. }
  14.  
  15. // read something from USART
  16. position = 0;
  17. do {
  18. while (!bluetoothReady());
  19. buffer[position] = readBluetooth();
  20. }
  21. while (buffer[position++] != '\r' && position < PREDEFINED_LENGTH);
  22.  
  23. // null character to close the string
  24. buffer[position-1] = NULL;
  25.  
  26. // reset position
  27. position = 0;
  28.  
  29. // send something back
  30. putrsUSART((const far rom char *)"\nMessage accepted\n\r");
  31. }
  32. }

Since these steps are the same as in the tutorial about the configurable news ticker we are not going into detail on it here. In this case one has to note that we a few other functions to our disposal that we use to wait for data (bluethoothReady()), receive data (readBluetooth()) and transmit data (writeBluetooth(BYTE data)). However, you can still use the standard RS232 functions such as putrsUSART.

We also quickly show the function needed for the news ticker effect.

  1. unsigned char newsticker(ram char *msg, unsigned char position) {
  2. char i,j;
  3. j=position;
  4. for (i=0; i<16; i++) {
  5. if (msg[j]==NULL)
  6. j=0;
  7. appendCharToLCD(msg[j]);
  8. j++;
  9. }
  10. if (msg[position+1]==NULL)
  11. return 0;
  12. else
  13. return position+1;
  14. }

Finally we add the function which will copy strings from the program memory to the data memory.

  1. void str2ram(static char *dest, static char rom *src) {
  2. while((*dest++ = *src++) != NULL);
  3. }

Now you can compile the program and program the Dwengo board.

Connecting with the computer

Once you have correctly connected the bluetooth module and programmed the Dwengo board, we can connect the bluetooth module to the computer. For this you first connect the Dwengo board to a power source (for example using a USB cable), this will also power on the bluetooth module and a green led should start flickering.
Next navigate in Windows to the Control Panel and chose Devices and Printers. Next chose "Add a device". If all goes well a wizard window appears in which the device linvor is shown (and possibly other devices such as your mobile phone).

bluetooth device linvor


Select linvor and click on next. Now you will be asked to select a pairing option. Chose the Specify the pairing code of the device:

koppelingscode opgeven


As code you should enter 1234:

code bluetooth module


Click on next and the device should now be successfully connected to the computer!

Testing of the program

You can now quickly test your program with the free ready-to-use program TeraTerm Pro External link. Download and install this program. We are going to setup a wireless connection with the Dwengo board. Check in the Control Panel > Administrative tools > Computer Management > Device Manager of Windows on which COM port the bluetooth module (the device linvor) is connected. Next start TeraTerm Pro and select as connection type serial and the correct COM port (in our example it is COM3). next click on OK. Navigate in TeraTerm Pro to Setup > Serial port ... and set the properties of the connection as shown in the screenshot and click on OK.
Connection settings
Also turn in the menu Setup > Terminal Local echo on, so you can see in the terminal of TeraTerm Pro what you are typing and press on OK.
Terminal settings
You now have a connection with the Dwengo board. Normally a message should appear on the screen once you turn on the Dwengo board or reset it.

Give message


You can now send a message to the Dwengo board. Type your message and press RETURN is you are finished. this message will appear on the LCD display of the Dwengo board. If you want you can send new messages.

Message accepted