Cerebot & BlueSmirf

From RoboCup

Jump to: navigation, search


BlueSmirf is a BlueTooth module that provides the virtual serial port functionality. On two of its output pins labeled as TX & RX (transmit, receive), it provides a usual serial port that is available on many single chip microcomputers, for example the Atmel's AVRs, which are the CPUs on the Cerebot board. BlueSmirf is thus an ideal communication device for remotely-controlling robots with Cerebot board, and debugging Cerebot programs. The serial port of the CPU can be used as the standard input and output and thus the standard C library functions, such as printf(), and scanf() will print and read directly from the terminal window running on a PC workstation after the BlueTooth connection between the BlueSmirf and the PC is created (see below).

Powering Up

BlueSmirf chip requires 3-6 Volts as its power source, thus the VCC from the Cerebot (3.3V) can be used as the power source. Be careful though, about the power consumption of all the devices that you attach to VCC, BlueSmirf takes 48 mA before the connection is established, then when the traffic is busy, it consumes about 33 mA. The CPU itself consumes less than 20 mA, and the power supply on Cerebot provides 500 mA.


The Cerebot has two serial ports UART0, and UART1. The UART0 uses same pins as the JTAG3 programmer, and thus the communication on this port can occur only after the programming cable has been removed. UART1 however can be used while the programming cable is still connected, and thus it is more convenient. The BlueSmirf pins are in the opposite order than the UART terminals available on the Cerebot: the Tx, and Rx pins are in opposite sequence. Thus we need to use a specially created cable, where these two wires cross. It is also required to remove the remaining two pins so that these signals will not be interfering in the connector and the cable. One has to be very careful about the orientation, because the BlueSmirf will be damaged if opposite polarity is connected! Once we have the connecting cables prepared, it is best to never remove them from BlueSmirf. The white mark on the free end connects to the PWR (one pin left to GND) of either the UART0 or UART1 terminals (these are available as connectors JD and JE on the Cerebot board). In our case, we will not use the CTS and RTS pins of BlueSmirf. Image:cerebot_bluesmirf.jpg


To be able to use the printf() and scanf() functions in your program, it is sufficient to tell the standard C library how to read and write one character - and these are (for example) the functions provided by the uart2.c from Proycon AVRlib (we adjust the behavior a little):

#include <uart2.h>

//outputs one character to UART1
static int uart1_putchar(char c, FILE *stream)
  if (c == '\n') uart1_putchar('\r', stream); //for Windows-like terminal programs
  return 0;

//retrieves one character from UART1
static int uart1_getchar(FILE *stream)
  char c;
  while ((c = uart1GetByte()) == (char)-1);
  uart1SendByte(c); //local ECHO
  return c;

static FILE uart_stdinout = FDEV_SETUP_STREAM(uart1_putchar, uart1_getchar, _FDEV_SETUP_RW);

int main() 
 stdin = stdout = uartstdinout;

 printf("Hello World!\n");

For more details, and a full example, see AVR calculator example program.

Another example: modem.zip - simple program for Cerebot, which connects its UART0 and UART1 ports.

Personal tools