Saturday, June 20, 2015

Raspberry Pi and Temperature Sensors

I just got 2 temperature sensors from Adafruit.
Here are mine after I soldered the headers on and wired them up on bread board.




They were very easy to use and didn't take much coding to get them up and running. They are both I2C and I was able to use my existing libraries to talk to them from the PI. I did put up code on github to show how to retrieve the temperature from both. The BMP180 has a few more things (ie. pressure, altitude, etc.) Though, the altitude wasn't very accurate to where I am. I am not sure about the pressure as I am not familiar with that... Either way, a fun project to get up and running!

Pi user space SPI

I finally had some time to play with a OLED (same one as my I2C one; SSD1306 chip), but this interface was SPI. I wanted to learn more about SPI and write a user space program in C++ that would run on my Raspberry Pi and drive the SPI OLED just like I had done for my I2C OLED. Did some digging on spidev and learned a lot. The commands to the OLED were the same as the I2C so I did not have to re-invent the wheel there, but the communication was the only difference.









Saturday, November 22, 2014

Emulating a HID Device

I've been hacking around with some Atmel microcontrollers and I thought I've give this project a try. Due to circumstances out of my control, taking a pedometer to work is not possible as it is not permitted on site. However, this pedometer is directly related to a health fund that gets money from my employer based on how active you are. I've already done something like this:
Yes, it get the job done, but at the expense of time... So, now I am going one step further. Using either a Pro Trinket or Teensy (images below), I was planning on faking things out. Instead of plugging this into my computer


I'll plug this in! :)



The next step was to setup setup the boards to emulate the USB HID device. For the Pro Trinket, I used VUSB and for the Teensy, I used LUFA. The VUSB API was a bit more involved and took a bit longer to get working as documentation seems sparse from my searches. Using Dean's LUFA library, it was very easy to setup and get configured. Since the Pro Trinket uses a slightly less sophisticated microprocessor (ATmega 328p), there is no USB support in that chip. However, Teensy's chip is the ATmega 32U4 which does have USB support and can use the LUFA stack. Either way, I thought I'd give both a shot.

After getting both configured, if I run the 3rd party software provided by Virgin Healthmiles, it now thinks I've plugged in the "real" pedometer. First step done! Drink a few beers and celebrate!

The next step is where I am currently stuck... Decoding their USB protocol. I have uploaded data many times using the real pedometer and captured the USB communication. Here is some sample data.

I've tried sending back the data I captured (using wireshark), but no dice. So they have some smarts built in, but I can't pinpoint it just yet. To complicate things more, the 3rd party software only supports Windows and Mac. Mac has good tools, but nothing to capture USB! I've tried to setup a VM on my linux box, but wine does not support all win32 API's the 3rd party software is calling. So I am writing the code on linux, uploading with avrdude and testing on Windows. Fun times.... Perhaps I should bit the bullet and install the development environment on windows. talk about humbug!

So.... my question for some of you readers out there. What are some common techniques used for this? What are things I can try to decode the data? My serial number seems to be encoded in the data, but I have yet to figure it out as things are either encrypted or on the bit fields and not at the byte boundaries. Any one have advice/suggestions as I'm all ears! Even better.... anyone want to join me with this project?!

Wednesday, July 30, 2014

Saturday, July 5, 2014

GPS with OLED

Wow, it's been a while since I've made a post... I've been playing around with the the Adafruit GPS for a while now as well as messing with different OLED's as well. I came across a board from @mikerankin that combined both into one with an Arduino Pro Mini. AVR programming has also been taking a lot of my spare time and so I thought this would be a great project to consolidate everything I've learned so my goal was to write native C code compiled with avr-gcc and upload it to the board with avrdude instead of using the Arduino IDE (though that works with this board and would be much easier; but where's the challenge there!). Here are a few pics from the work in progress...

These pictures show the main screen and the board itself. Upper left corner is the temperature reading, upper right is the number of satellites that the GPS receiver is connected to. Bottom shows the format of the time (12h or 24h format is supported). Bottom right is the date and in the middle is the time.

This picture shows the trip summary as it tracks distance much like an odometer of a car. I changed the distances from metric to US measurements, but forgot to change the labels accordingly (oops! I know what I'll be doing after I post this)
This next screen shows the altitude (upper left), number of satelliets (upper right), course (below number of satellites) and speed in miles per hour.
This is the back of the GPS Board and you can see the Atmega 328 microprocessor , FTDI chip, resistors, LEDs, etc. You can refer to Mike Rankin's page for schematics and other details.

These pictures show the status LED for the lipo battery (red is charging and green is charged).

Lastly, this is a side view of the board. You can see the GPS module that the OLED hovers above on.

There are many more features that I have not discussed (ie. resetting the trip meter, saving a lat/lon position, saving data, etc). Those are all included in the original sketch which was done by Karman and posted to his blog. However, that sketch didn't work out of the box for me and kept crashing. I've since modified it to toggle between metric and US measurements, fix the crashing bug, and a few other minor fixes with some graphics and font modifications.

Saturday, March 22, 2014

ATtiny85 and V-USB on a breadboard

Using an ATTiny85 chip, I programmed it to emulate a USB device and stuck it on a breadboard with a mini USB breakout board. It's not the nicest layout on a breadboard, but it gets the job done. Plugging the USB cable into the computer, it runs the code and a USB slave device shows up. I have a custom driver communicating with the chip over USB.

Thursday, March 6, 2014

Trinket with V-USB

A few months ago I stumbled upon Joonas Pihlajamaa's tutorial about AVR ATtiny USB Tutorial. His tutorial is very informative and got me interested in communicating with AVR chips via USB. In his tutorial, he used an ATtiny2313 chip on a breadboard with different components to demonstrate things. Since, I'm not an electrical engineer and don't know too much about putting all that together I didn't pursue his setup.

In came Adafruit's Trinket which is conveniently mounted on a PCB and has a USB interface with a ATtiny85 chip. I then set out to try to replicate his tutorial on this hardware. I didn't know much about avr-gcc so I got to learn about that in the process. In my prior post, I detailed out how to setup your environment, compile a simple program, and upload it to the trinket so refer to that if you are reading this first.

A lot of the magic happens in the V-USB library which does most of the heavy lifting for us. Since the ATtiny85 doesn't have a USB stack on that chip, we must use this library and software to emulate it. The configuration from Joonas' tutorial was a bit different as port's and pins differ between the ATtiny2313 and ATtiny85. 99% of the code is already listed in his tutorial so I am not going to re-invent the wheel here as you can refer to his tutorial for the code. Here is the hex file you will need to upload to the trinket. Using his usbtest binary, you can interface with your trinket over USB!