Showing posts with label raspi. Show all posts
Showing posts with label raspi. Show all posts

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.









Wednesday, July 30, 2014

Sunday, February 9, 2014

I2C Library for BBB and Pi

I've been getting numerous requests to share my I2C Library. There are a few other things I'm adding to my github repository before I publish it, but in the meantime, here is the I2C library. Using and/or downloading it means you do so at your own risk.

This is nothing fancy as I only did what I needed to for my projects. This library works on both Raspberry Pi and BeagleBone Black for my Adafruit 128x64 OLED module.

i2c.cpp and i2c.h

Saturday, July 13, 2013

Raspberry Pi GPIO with RGB LED

I was playing around more with the wiringPi library and a Red Green Blue LED. I have a simple setup that will blink the led in each color. From the video, it's a bit tough to distinguish between blue and green so I included a few pictures of each color as well.

 

Monday, July 8, 2013

GPIO using the Raspberry Pi


After getting my OLED and GPS working, I wanted to mess around with the GPIO pins so I bit off something simple. Here is what my setup looks like.
  • Raspberry Pi
  • Raspberry Pi T Cobbler
  • Raspberry Pi Ribbon Cable
  • Breadboard
  • Two 1 KiloOhms resistors
  • Two 10 KiloOhms resistors - pull up resistors
  • 2 momentary pushbuttons
  • Jumper wires
In this setup, pushing the button will drive the signal low. To keep things simple and just illustrate the point, pushing the button(s) will just print out a message to stdout. In doing some research, I came across Gordon's wiringPi library. I incorporated this into my code so I didn't have to reinvent the wheel! It is pretty simple to use for my C++ application. I started out the simple way and had a loop to check the pin status and act upon it if it has changed. However, that doesn't fit my end goal so I got a bit fancier with the implementation, but the good news is that it is supported by wiringPi. The fancier implementation is to use interrupts and to have a function pointer called when the interrupt is detected. Below is the code to drive this circuit. Currently, the circuit does bounce so debouncing code will need to be added to normalize this, but hopefully this illustrates the point.
#include <iostream>
#include <wiringpi.h>

// These are wiringPi pin numbers from http://wiringpi.com/pins
#define BUTTON_1     7  // pin 7 on pi
#define BUTTON_2     3  // pin 15 on pi

using namespace std;

void interruptHandler ()
{
   cout << "in interruptHandler()" << endl;
}

void interruptHandler2 ()
{
   cout << "in interruptHandler2()" << endl;
}

int main ()
{
   if (wiringPiSetup() < 0)
   {
      cout << "uniable to initialize wiringPi library!" << endl;
      return 1;
   }

   if (wiringPiISR (BUTTON_1, INT_EDGE_FALLING, &interruptHandler) < 0)
   {
      cout << "Unable to register interrupt handler for BUTTON_1!" << endl;
      return 1 ;
   }

   if (wiringPiISR (BUTTON_2, INT_EDGE_FALLING, &interruptHandler2) < 0)
   {
      cout << "Unable to register interrupt handler for BUTTON_2!" << endl;
      return 1 ;
   }

   // wait for interrupt, but don't consume 100% of cpu
   while (1)
      delay (100);

   return 0;
}

Tuesday, July 2, 2013

Raspberry Pi GPS and LCD


Building upon the I2C and OLED from my previous posts, I connected a GPS and used the same OLED to display data. Currently, latitude, longitude, speed, and course are the values I chose to deal with first, but gpsd has much more data you can get at. I chose to do all my development with C++, but a quick google search shows many examples using Python. Once I get my C++ code working and finalized, I'll port things to Python.

The OLED is connected via I2C to the Raspberry Pi and the GPS is using the hardware UART on the Pi. The hard part is now out of the way! Next up, save the GPS data (in KML) to a file and plot that file on Google Earth.

Sunday, June 23, 2013

Bitmap on Adafruit 128x64 using a Raspberry Pi


It's been a while, but I *finally* got my Adafruit 128x64 OLED working to display a bitmap image. From the Adafruit forums, unfortunately (or fortunately!) they currently do not have support for C++ libraries for this display on the Raspberry Pi, which is why I had to write my own. It was also a great learning experience! The code is written in C++ so I plan to use it for my BeagleBone Black as well. I believe nothing needs to be changed, but just recompiled for that platform, but I'll test that a bit later.

The OLED memory map isn't linear; probably because it's primarily use for rendering output in text which is typically in the form of a 5x7 font. Thus, the biggest challenge is to read and rotate the data. I used an 8 byte array as the memory map is aligned that way. So reading the 8 bytes from the bitmap and rotating those bytes from being horizontal to being vertical is the biggest challenge. Essentially, that  is what I did to take advantage of how I write out the bytes. I have one method that writes out the bytes for both text and bitmap images.

Next up... Hooking up a GPS receiver and getting the output to display on the OLED. Hopefully, this should be a bit easier since I now have a library to interface with when using the OLED.

Thursday, June 13, 2013

Raspberry Pi and 128x64 OLED




I recently purchased a LCD display for some projects I have going. Initially, I hooked it up to my arduino since Adafruit has libraries already written that can let you run things easily (just has to solder the header pins to the PCB and you are in business). Their library support is great and it makes things easy to use and they have some working examples too. Unfortunately (or fortunately!), if you plan to use this for a Raspberry Pi or Beaglebone Black, you are not so lucky as there are no libraries that you can download and use for those (yet!). Since I wanted to learn more about interfacing with hardware/firmware, this was a great place to start. The driver chip on the OLED board is a SSD1306 one and the datasheet is available here. I have mine connected to the PI via I2C. Note, by default, the OLED comes with SPI enabled, so closing 2 gates on the back with a little solder needs to be done to enable I2C. Just using a 2 jumper wires for clock and data, we are in business!

I was able to get some simple text up on the LCD and played around with placement (ie. centered and left justified). For me, it was easier to develop on ubuntu and copy my files over to the PI. It allowed me to do remote debugging and my core i7 was much faster than the processor on the PI. I still have a bit more functionality to add but so far it has been an enjoyable project to work on.

Friday, June 7, 2013

Reformat SD card after using it in Raspberry Pi

If you try to use your SD card after having used in your Raspberry Pi, you will notice your OS will not recognize it. OS X and Windows, it's pretty straight forward to reformat, but Linux is a bit more tricky, but here are the steps.
  1. Mount the SD card
  2. Find where the SD card is mounted. You can do this with the
    mount
    command. If you are not root, try
    sudo mount
    The SD card will be mounted to something like
    /dev/sdbx
    where x is a number.
  3. Delete the partitions from the SD card. The command to do this is
    sudo fdisk /dev/sdbx
    • p is the command to list the existing partitions
    • d is the command to delete the partition
    • delete all partitions on SD card
  4. Create a new partition
    • n is the command to create a new partition
    • p is the command to to create a primary partition
    • Enter the sector size 8192
    • press Enter to select the default last sector
    • t is the command to change the partition type
    • We want FAT32, so type b
    • w is the command to write the changes to disk
  5. Now we have our partition created, we need to format it. We can do that using this command
    mkdosfs -vF 32 /dev/sdb1
  6. That is it. You should now see this drive as a thumb drive again.

Tuesday, June 4, 2013

Compiling for Raspberry Pi



Installed wheezy 7.0 on an 8GB micro SD card and booted my raspi. ssh'ed in and was able to test out my cross compiled program (compiled on linux). Wasn't as painful as I thought... So I took the next step and setup remote debugging as well with gdbserver. I can now compile the code on my linux machine, run it on my raspi, and also debug it from my linux machine. Pretty cool!