Pages

Sunday, July 9, 2017

Raspberry Pi 3 Alarm System

What is this mess, you might ask?

Well this is the final prototype for my Raspberry Pi 3 Alarm system. It uses the USB keypad in the upper left corner to input the correct code, the entry and exit delay beeper is in the lower left of the photo beside the keyboard, and the LED's showing what is going on is on the breadboard just above the keyboard. You cannot see the PIR sensors, that I have mounted on the pole of the shelf that is visible in the upper right of the picture.

The next step (today) is to mount all of the components on a board and see how everything will fit into the case!

I'll post a final pic once I have everything mounted in the case.

Thanks for viewing!
Robin

Sunday, April 30, 2017

Connecting Raspberry Pi 3 and Arduino

WOW, I cannot believe that it has been over a year since my last post. Time flies when you're having fun!!!

I've decided it was time to update the last post (it's only been about 16 months!)


  1. Install Jesse Raspbian with Pixel 2017-04-10
  2. Go thru the configuration
    1. Change the pi password
    2. Change the Pi Hostname
    3. Don’t automatically login to ‘pi’ user
  3. Under the Interfaces Tab:
    1. Camera = Disable
    2. SSH = Enable
    3. SPI = Enable
    4. I2C = Enable
    5. Serial = Disable
  4. I don't change anything under the Performance Tab
  5. Under the Localisation Tab:
    1. Change the locale to Canada (English)
    2. Set the Timezone to Canada (America) > Mountain (Edmonton)
    3. I’m still having a problem with changing the keyboard layout
      1. It is a noted problem on the Raspberry Pi Forum
      2. Still using sudo raspi-config to config to Canada > English
  6. sudo apt-get update
  7. sudo apt-get upgrade
  8. sudo adduser robin
  9. add robin to same groups as pi user (dialout for arduino)
  10. sudo apt-get install arduino
  11. sudo apt-get install arduino-mk
  12. Modify avrdude.conf to work with GPIO pins
    1. sudo nano /etc/avrdude.conf
    2. Ctrl-W to find the gpio reference, and uncomment the following lines
    3. programmer
      1. id = "linuxgpio";
      2. desc = "Use the linux sysfs interface to bitbang GPIO lines";
      3. type = "linuxgpio";
      4. reset = ?;
      5. sck = ?;
      6. mosi = ?;
      7. miso = ?;
      8. ;
    4. And change the ? to;
      1. reset = 8 (GPIO # not Actual pin #24, CE0)
      2. sck = 11 (Actual pin #23, SCLK)
      3. mosi = 10 (Actual pin #19, MOSI)
      4. miso = 9 (Actual pin #21, MISO)
    5. Wire up the Arduino ICSP header as follows:
      (RESET is closest to IC)
      -------------------
      | MISO    +5V |
      | SCK     MOSI |
      | RESET  GND |
      -------------------
      1. RESET to Raspi pin 24
      2. SCK to Raspi pin 23
      3. MISO to Raspi pin 21
      4. +5V to Raspi pin 2
      5. MOSI to Raspi pin 19
      6. GND to Raspi pin 6
    6. Type in sudo avrdude -v to ensure avrdude is responding
    7. Type in sudo avrdude -p atmega328p -c linuxgpio -v to ensure avrdude can communicate with the arduino
    8. As mentioned in my previous post, I copy my raspi-git github directory to each Raspi to make it easier to copy common files back and forth.
    9. cp -r ~/raspi-git/Uno/Blink ~ (to copy the blink directory to my home directory)
    10. move to the ~/Blink directory and run the following to download the software into the arduino
      1. sudo avrdude -p atmega328p -c linuxgpio -v -U flash:w:./build-uno/Blink.hex:i
      2. If all goes well this should upload the Blink.hex program to the arduino
    11. Check the Makefile for the following lines:
      1. BOARD_TAG = uno
      2. ARDUINO_PORT = /dev/ttyACM0
      3. ARDUINO_LIBS =
      4. ARDUINO_DIR = /usr/share/arduino
      5. include /usr/share/arduino/Arduino.mk
    12. Check it by modifying the ~/Blink/Blink.ino file and recompiling it
      1. nano ./Blink/Blink.ino
      2. Change the blink rate
      3. Ctrl-x to save
      4. make
      5. sudo avrdude -p atmega328p -c linuxgpio -v -U flash:w:./build-uno/Blink.hex:i
      6. the changes should be apparent on the Arduino LED

Wednesday, December 16, 2015

Avrdude 6.1

I just installed the latest version of Raspbian Jessie 2015-11-21 for my Pi 2's. I found that now when I installed the arduino package, it comes with avrdude 6.1. So I don't need to link to the adafruit repository anymore. Here is a list of the steps I take to install Jessie, Arduino, Arduino-mk, and check that I can communicate between the Arduino & Raspberry Pi 2 via Serial. You'll note that I clone my git repository where I keep all of my files as I'm working on them. I find this extremely useful since I'm working on the files on my Pi2 or Gertduino/PiB at home, or the same setup that I have at work:
  1. Install Jesse 2015-11-21
  2. Go thru the configuration
    (Menu > Preferences > Raspberry Pi Configuration)
    1. Under the System Tab:
      1. Expand the filesystem
      2. Change the pi password
      3. Change the Pi Hostname
      4. Don’t automatically login to ‘pi’ user
    2. Under the Interfaces Tab:
      1. Camera = Disable
      2. SSH = Enable
      3. SPI = Enable
      4. I2C = Enable
      5. Serial = Disable
    3. I don’t change anything under the Performance Tab
    4. Under the Localisation Tab:
      1. Change the locale to Canada (English)
      2. Set the Timezone to Canada (America) > Mountain (Edmonton)
      3. I’m still having a problem with changing the keyboard layout
        1. It is a noted problem on the Raspberry Pi Forum
        2. Still using sudo raspi-config to config to Canada > English
  3. sudo apt-get update
  4. sudo apt-get upgrade
  5. sudo adduser robin
  6. sudo visudo to give robin the same rights as pi user
  7. sudo apt-get install arduino-mk
  8. sudo apt-get install arduino (add robin to dialout group)
  9. Make a link to the Arduino.mk file:
    ln -s /usr/share/arduino/Arduino.mk ~/Arduino.mk
  10. Copy the original avrdude.conf file into my home directory
    1. cp /etc/avrdude.conf ~/avrdude_gpio.conf
  11. Modify it to work with the GPIO pins
    1. nano ~/avrdude_gpio.conf
  12. Aff the following lines at the end of the file:
    1. # Linux GPIO configuration for avrdude
    2. # Change the lines below to the GPIO pins connected to the AVR
    3. programmer
    4.  id = "pi_1";
    5.  desc = "Use the Linux sysfs interface to bitbang GPIO lines";
    6.  type = "linuxgpio";
    7.  reset = 12;
    8.  sck = 24;
    9.  mosi = 23;
    10.  miso = 18;
    11. ;
  13. With the Arduino connected to the Raspberry Pi, run the following line to make sure the Raspi can see the arduino:
    sudo avrdude -p atmega328p -C ~/avrdude_gpio.conf -c pi_1 -v
  14. cp -r ~/raspi-git/Python ~ (to copy the Python directory to my home)
  15. cp -r ~/raspi-git/Uno ~ (to copy the Uno directory to my home)
  16. Goto the .hex file @ ~/Uno/Serial/Voltages/build-uno/Voltages.hex & run:
    sudo avrdude -p atmega328p -C ~/avrdude_gpio.conf -c pi_1 -v -U flash:w:Voltages.hex:i
  17. If you overwrite the bootloader, reload it by going to:
    cd /usr/share/arduino/hardware/arduino/bootloaders/optiboot/
    and running the avrdude line with the optiboot_atmega328.hex file

Wednesday, December 9, 2015

Raspberry Pi takes over the world


OK, if not the world, then 1 outlet at a time!!!
This is a pic of a single relay that is controlled by my Raspberry Pi.
Red = 5VDC, Black = Ground, White = Pin23 (active high)
And an old pc power cord split in 1/2 and a female end installed.
The Ground and Neutral leads feed straight through from the input to the output
The relay switches the hot lead and runs a battery charger drawing 5 Amps AC.
The relay is rated for 10A @ 277V
The Raspberry Pi runs off of my solar array at home and because I have so many items tied to them:
     3 Raspberry Pi's
     1 x 12V HP switch
     1 x Kenwood HF Amateur Radio
     1 x LDG Antenna Tuner
     1 x Radio Shack HTX-242 VHF Amateur Radio

Most days I have enough solar energy to power all my devices.
However if I get several cloudy days together, the voltage can drop and my charge controllers shut down.
Then my Raspberry Pi's shut down...... And that makes me cranky.....

So I have an Arduino monitoring the battery voltage and sends that data via serial to the Raspi
If the battery voltage drops down too much due to lack of sunlight, the charger is turned on for a charge cycle (typically 6-8 hours), and then shuts off.

I plan on making quite a few of these for the many different 120VAC loads that I want to control from my Raspi.
Thanks for viewing;
Robin

Monday, December 7, 2015

Upgrade from Halogen to LED


So, what do you do when you want to change from the small halogen lamps to LED?
Problem is that many halogen power supplies are rated @ 12 VAC, and LED's require 12 VDC.
What I've done here is to add a bridge rectifier and 1000uF/35V Capacitor to a small adjustable power supply.
Packed it in a small Hammond case and works like a charm!!!
I can feed this from the halogen supply with AC, and adjust it to deliver clean 12VDC to my LED's
I've got a customer with quite a few of these lites in all of their bathrooms, etc and it is very difficult to get at the halogen power supply.
So I can simply add this inline at the beginning of the lamp string(s), and presto! even more energy efficient lighting!!!
Thanks for viewing,
Robin

Friday, December 4, 2015

Raspberry Pi & Arduino talking nicely!!!


This is a picture of success!!!
Once again many thanks have to go out to Tony DiCola of Adafruit for publishing his most AWESOME tutorial on Programming an Arduino using the Raspberry Pi GPIO
This enabled me to upgrade to Avrdude 6.1 from the Adafruit Repository and then program the Arduino thru the ICSP header from the GPIO pins.
.... And the bonus is that I can leave my serial connection from the Raspi to the Arduino connected while the programming is taking place!!!!!
So follow his steps to download the new version of Avrdude to your Raspi and hook up the pins from the GPIO header to the Arduino ICSP header.
Test run the program to ensure it can see the Arduino and you're off!
You need to directly upload a .hex file using Avrdude, so the Arduino IDE will do the converting/building for you from .ino to .hex.
I've been using Arduino-mk to upload my .ino sketches (since I like using the command line), so now I just use Arduino-mk to make the sketches, and Avrudude61 to upload them.

The following steps outline Tony's process:

Step 1 - Add the Adafruit repository to the Raspi list using the command:
curl -sLS https://apt.adafruit.com/add | sudo bash

Step 2 - Install the new version of Avrdude by running the following:
sudo apt-get install avrdude 

Step 3 - copy the /etc/avrdude.conf file to my home directory and rename it ~/avrdude_gpio.conf

Step 4 - add the following test to the end of the .conf file in my directory:

# Linux GPIO configuration for avrdude
# Change the lines below to the GPIO pins connected to the AVR. 
programmer
    id = "pi_1"; 
    desc = "Use the Linux sysfs interface to bitbang GPIO lines"; 
    type = "linuxgpio";
    reset = 12; 
    sck = 24; 
    mosi = 23; 
    miso = 18;
;

Step 5 - run the following command to confirm connection to the Arduino:
sudo avrdude -p atmega328p -C ~/avrdude_gpio.conf -c pi_1 -v

Step 6 - Once successful, goto a directory with the .hex file you want to upload to the Arduino and run the following command:
sudo avrdude -p atmega328p -C ~/avrdude_gpio.conf -c pi_1 -v -U flash:w:Blink.cpp.hex:i 
>>> and you should be able to watch Avrdude upload the sketch and verify it.

++++++++ Oh Yeah, and this is my first post done completely on my Rapsberry Pi 2 in the picture!!!! A little slower than I'm used to, but works great!!! +++++++

Sunday, November 15, 2015

Arduino & Raspberry Pi fighting


This has been my focus over the last couple of weeks (after my day job of course and the other courses I'm teaching!!!)

The top left is of course a Raspberry Pi2
To the right is an Arduino Uno clone
To the right of it is a relay board with 2 x 5VDC relays triggered from the Uno
And just above the relay board is my 12V > 5VDC power supply.

The bottom board and breadboard is a Raspi B model with a Gertduino board plugged in above it (you see 2 blue LED's lit). This is my prototyping setup for the Raspi > Uno Communications.

The Arduino powers on the left hand relay (you can just make out the Red LED) which powers on the Raspberry Pi (Raspi).
As well, the Uno monitors my battery voltage on Analogue A0 pin (batteries are not pictured).
The Raspberry Pi polls the Arduino for the Battery Voltage & if the battery voltage drops to 10.5VDC, the Raspberry Pi goes into shutdown (via a python script).
The Arduino continues to monitor the battery voltage and if it drops down to 10VDC, it shuts off the relay which powers the Raspberry Pi down safely.
Once the power is restored, the Arduino powers up and then powers up the Raspberry Pi safely.

The problem I've been struggling with though, is when the Raspberry Pi polls the Uno via the USB Cable (shown unplugged from the Uno in the picture above) the Uno resets every time which changes it's Digital output pins, which shuts down the Raspi......
Thanks to the great folks on the Arduino Forum (UKHeliBob & Robin2) I learned that when the Raspi talks to the Uno via the USB cable it includes resetting the Uno which resets the Digital pins......
What I needed to do was to talk via the 3 wire Serial (Tx, Rx, GND) between the Raspi & Uno and now no problems!!!!
You can see there is a purple and grey wire, as well as a Green/White pair  running from the Uno to the Raspi. The Green/White pair have a set of resistors to drop the Uno 5VDC down to the Raspi 3.3VDC for the Serial comms. the other wires are the ground connections (1 redundant)

So it is a bit more work, to use the USB cable to program and then switch over to the 3 wire serial for comms, but really to see it working properly is not problem at all!!!