This tutorial shows how to send ADC sampled data to terminal using serial port.
The object of this tutorial is to show another kind of usage of REOBoard with serial port. Using serial port may seem a little bit out of recent years' developments but as serial port is very simple, robust and still widely used, it may be worth
spending a few hours with it.
Again, we will use ReoBoard for this, but it can be easily ported to any board featuring at least 2 ports.
. One SPI for the accelerometer
. One UART for the serial port.
We will first wire the accelerometer on the board and test it. The accelerometer chosen here is a BMA150. The reason is that among the available accelerometers, it's the chip with the largest bandwidth (3 kHz). It has been soldered to a 10 x 10 mm board.
Using this accelerometer is quite straightforward. Wire MISO, MOSI, CLODK, VCC, GND and INT and that's about it.
As for the serial port, very few computer have one, but it's possible to find cheap adapters, and that's what I have used.
The program can be downloaded from here. There are 3 files. The first one is only focused on sending data to a PC terminal using serial port. The second introduces a timer instead of the delay function, and the third one actually reads analog data and sends its value as a string to the terminal.
Before starting, you have to wire a TTL to RS232 converter chip to the board. These chips exists in many makers and in various shapes. I have used a TSSOP chip made by Intersil. Connect only GND, RX and TX to the board. Remember that device's TX is to be connected to CPU's RX and similarily CPU's TX has to be connected to device's RX. You can ignore flow control signals which will not be used in this operation.
For the first program, what you have to do is to download Teraterm. Teraterm is a free terminal program. Once installed, plug a USB / serial converter and connect a serial cable to your hardware. I'm using a small level converter in which a 2.5mm jack is used.
Sending bytes to Teraterm
In the first part of the tutorial, we just configure a serial port with baud rate = 922 k. Teraterm should be configured the same way. As for the data format, it's 8N1 (8 bits, no parity, 1 stop bit).
The programs should be compiled with 00Common for the commonly used functions. It should compile without any issue except possibly minor path problems.
Using a timer
As shown in previous tutorials, the main program does nothing except putting the program to interrupt wait state. This time, we have removed the while loop and moved the string send function into a separate function.
The last step is pretty much the same except that we read the ADC at timer interrupt and send its value to the terminal. You may remember that a potentiometer had been used previously. You may use the same kind of expermiental hardware, or you may leave the ADC input floating. In this latter case, touching the input will greatly change the ADC value.
We have shown how to use serial port for data transmission from ReoBoard. At this point, the user has to be careful: RS232 is not meant to be used at such high rates There are some well defined values for bit rate vs cable length. From my point of view, they are extremely conservative.
922kbps seems to work well. However, I haven't made any bit error rate measurement and I don't guarantee the validity of this code. I have tested it, it works on my desk, maybe not on yours. You have been warned!
In case it doesn't work, try to drop the bit rate. For example 115200 is quite safe.