Everything (Almost) WorksÉ
A few weeks ago I was called on to present in class. When I talked about my final project (now changed) I wanted to be able to sense the amount of beer left in a bottle. Neil recommended I use a step response sensor to get the job done. While I am no longer doing this as my final project, I still plan to do it one day and I needed a place to start while I thought more about my barcode scanner which will be the input of my final project.
I copied the tx-rx step response board from the course site. Milled, stuffed, programed. My first challenge of the week occurred when I tried to run the python script. It said that I did not have the serial module.
Here are all the ways I tried to fix it:
á Download PySerial
á Uninstall python, reinstall with homebrew, download pip, install PySerial with pip. Pip says I already have it
á I still had multiple instances of python. So I dragged and dropped Serial into every python package I could find
It continued to not work. Any other suggestions would be greatly appreciated.
Rob lent me his computer and I was able to watch my sensor in action!
Here are pictures of the sensor in action:
Glass Empty: Value=10742.5
Glass Half Full: Value=19990.7
Glass Full: Value=23434.8
WhatŐs really going on?
I have had experience working with Arduinos before and this week I grew an appreciation for all of the things it does in the background. Here are some cool things I learned about electricity and bit banging.
To sense the change in capacitance a known pulse is sent to the transmit pads. Those electrons leave the pad and go off into the world. They are looking for somewhere to go, many of them will reach the receive pad but not all. If the pads are closer together, or there is some medium between them that allow the electricity to flow better then more electrons will arrive on the receiving pad. If they are far away or some non-conductive medium is placed between them less will travel.
A comparison between the pulse sent and the pulse received is used for calculating the value.
Sending a 10-bit message with 8-bits (Understanding the code):
For each reading of the step response sensor there are two values, up and down. Up being the value sensed when the pulse was high and down being the value read when the pulse was low.
Up and Down are defined as 16 bit unsigned integers
static uint16_t up,down;
The Analogue to digital converter returns a value between 0 and 1023. Which is represented as 10 bits.
up += ADC;
down += ADC;
Messages are sent over the serial communication as chars which are only 8 bits. The following visualization helped me to understand.
The first line shows the bits of the uint16_t. In the initiation of the ADC the code specifies that the important bits are right adjusted.
| (0 << ADLAR) // right adjust
So we know that it is the 10 right most bits that are our value, the rest is leftover from the last time the memory was used.
We then break the 10 bits into 2 (leftmost) high bits and 8 (rightmost) low bits. The high bits are multiplied by 256 and added to the low bits to a value between 0-1023.
These can now be sent as two 8-bit chars. Using a bit shift (up>>8) to send the second half.
put_char(&serial_port, serial_pin_out, (up & 255));
put_char(&serial_port, serial_pin_out, ((up >> 8) & 255));
Trials with the barcode scanner:
For my final project I want to use a barcode scanner as the input device. I got this MCR12 scanner out of an older version of the robot I am modeling my final project off of. (http://kinderlabrobotics.com/kibo/)
I was able to get my computer to think it was a USB keyboard and when I read the barcodes they show up as keystrokes. The manual says it is possible for the device to output as RS232. I went through the configuration processes to do so. It didnŐt work. To debug I tried:
á Putting it on the receive line of my Echo board from a few weeks ago and looking for Echo over FTDI
á Connecting it to FTDI cable and reading serial through CoolTerm
á Looking at it with Osciliscope showed no signal and a constant voltage of 3V.
If I canŐt get it to work I could keep it as USB keyboard and try V-USB (although I donŐt really know how that works) to convert to serial, or run it through a raspberry pi, or buy one of these (http://www.hobbytronics.co.uk/usb-host-board-v2) but they are only sold abroadÉ