---

Sunday, January 22, 2017

On Switch for Raspberry Pi

When you gave finished using your Raspberry Pi, you should really shut it down, otherwise, its possible to corrupt the SD card image which would mean you having to reinstall Raspbian. Having shut-down your Raspberry Pi you can get it to boot up again by unplugging and plugging the USB lead, but a neater solution is to add a reset button to your Raspberry Pi.

Most models of Raspberry Pi have a connector just for this purpose.

  






You will Need

* 2 pin header
* A push button with female header connectors.






For the push button, you can either use a scavenged reset switch from an old PC, or, as I have here, a MonkMakes Button, which is sold as a twin-pack on Amazon.com or Amazon.co.uk.








Construction

First of all, you need to identify the two holes in your Raspberry Pi board that you need to make connections to. These are circled in yellow in the figures below, for the Raspberry Pi models that I have. The location of this has moved with pretty much every Raspberry Pi release. The two pins will either be labelled RUN or P6

Raspberry Pi 3 model B


Raspberry Pi 2 model B


Raspberry Pi model B ver 2


Raspberry Pi Zero


Raspberry Pi A+




Having found where the pin headers need to go, if you have soldering equipment, then solder the pin header into the socket as shown here:




If you want to avoid soldering, then you can do so as follows. First push the plastic part of the header pin down as shown below:



Then push the header pin through from the underside of the board and push the header sockets of the MonkMakes Button into the header pins so that the Pi is the filling in a header sandwich. As long as the switch is not moved around too much, it should stay connected and make a reasonable contact, but soldering is better if you can.


Shutting Down and Starting

To test out your modification, power up your Raspberry Pi and then shut it down, by selecting Shutdown from the raspberry menu.



Then select the option Shutdown.



After a while the screen will close down and the Pi will go into a 'halt' mode, where it uses minimal power and is basically in standby mode.

Now to start your Pi, all you need to do is press the button and it will start to boot up!



If you liked this article, you will probably like my Raspberry Pi books:

 






Wednesday, August 31, 2016

Introducing the Joey Raspberry Pi Display

Gooligum Electronics (could they be more Australian?) recently sent me a Joey board to play with.



These boards are incredibly good value at $8 (the American sort of dollar) and a neat design that uses offset holes in the PCB so that it will slide over your Raspberry Pi's GPIO connector while leaving you access to the pins for other uses. This works well, with just the right amount of offset to ensure a good connection without bending the pins.

To make use of the Joey, you'll need to go and get the Python library for it.

Install it using the command:

git clone https://github.com/gooligumelec/Joey-support-Python-code.git

The Joey board also uses I2C so you will need to enable I2C which you can do from the Preferences->Raspberyy Pi Configuration menu option.



You'll also need to install smbus using the commands:

sudo apt-get install python-smbus

I tried out one of the example programs inside the folder joey_clock.py

cd Joey-support-Python-code
sudo python joey_clock.py



The Joey also has a row of three jumpers on the front that you can attach buttons to. Just the job for a Squid Button!



I added the Squid Button so that the clock could switch between showing the hours:mins or seconds. The modified program is listen below:

import time
import datetime
from joey_support import joeyBoard

display = joeyBoard()

show_seconds = False

# Continually update the time on the "Joey" 4 char, 7-segment display
while(True):
  if display.getJumpers() == 7:
      show_seconds = not show_seconds
  now = datetime.datetime.now()
  hour = now.hour
  minute = now.minute
  second = now.second
  if show_seconds:
      display.writeInt(0)
      display.writeDigit(3, int(second / 10))   # Tens
      display.writeDigit(4, second % 10)        # Ones
  else:
      # Set hours
      display.writeDigit(1, int(hour / 10))     # Tens
      display.writeDigit(2, hour % 10)          # Ones
      # Set minutes
      display.writeDigit(3, int(minute / 10))   # Tens
      display.writeDigit(4, minute % 10)        # Ones
  # Toggle colon
  display.setColon(second % 2)              # Toggle colon at 1 Hz
  # Wait one second
  time.sleep(0.5)

Monday, August 8, 2016

Use a Raspberry Squid with a Micro:bit

The Raspberry Squid is an RGB LED with built-in resistors originally designed for the Raspberry Pi. But you can also use it with a BBC Micro:bit.


You can find instructions for making a Squid from https://github.com/simonmonk/squid or buy a ready-made one by MonkMakes.

You will also need a Micro:bit and a breakout board such as this one from Kitronik.

Connect up the Squid with the black lead to 0V, red to pin0, green to pin1 and blue to pin2.


Here's the script!


Friday, February 5, 2016

A Simple LED Clock using Spark Core or Particle Photon

Having a spare Spark Core doing nothing, it struck me that it would be very easy to pair it up with a large 4 digit 7 segment I2C Adafruit display that I had and make a clock. What's more, because the Spark Core is connected to the Internet via my home network it can get its time from a time server and always be accurate.



Hardware


To make this build, you will need:


  • A Particle Photon or Spark Core
  • I2C backpack LED display (Adafruit product ID 878 or 1270)
  • Half breadboard
  • 2 x 4.7k resistors
  • 5 x male to male jumper wires
I used Adafruit's large display (1270) which has an extra pin to the left of the + pin that supplies power for the control logic, separate to the LED power. The breadboard layout below will work for the large display and the smaller display, just make sure that whichever display you use, the yellow lead goes to the C connection of the display.

The displays are also available in other colors if you check Adafruit's website


Software

Go to http://particle.io and select the BUILD option to open the web IDE. 

Create a new 'App' and call it Clock.

This project requires the SPARKTIME and ADAFRUIT-LED-BACKPACK LIBRARIES, so click on the libraries button, find each of these libraries in turn and click USE THIS LIBRARY selecting your new Clock app when asked to select the app.

Now you can paste the following code into your App. Note that the includes should already be there if the libraries have been imported correctly.

You will need to change your time zone offset on the last line of setup.

That's it - the display should start as soon as the Photon or Core resets. 



#include "SparkTime/SparkTime.h"
#include "adafruit-led-backpack/adafruit-led-backpack.h"

Adafruit_7segment matrix = Adafruit_7segment();
UDP UDPClient;
SparkTime rtc;

unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;
int colon = false;

void setup() {
  matrix.begin(0x70);
  matrix.setBrightness(15);
  rtc.begin(&UDPClient, "north-america.pool.ntp.org");
  rtc.setTimeZone(0); // gmt offset
}

void loop() {
    
  currentTime = rtc.now();
  int min = rtc.minute(currentTime);  
  int hour = rtc.hour(currentTime);
  matrix.print(hour * 100 + min, DEC);
  colon = ! colon;
  matrix.drawColon(colon);
  matrix.writeDisplay();
  delay(500);
}


If you enjoyed making this project, and want to learn more about programming and using the Photon, check out my book on the Photon.


Saturday, November 14, 2015

Introducing the Raspberry Squid

Sometimes its just really handy to be able to plug something into your GPIO pins without having to get out breadboard and jumper wires.

The Raspberry Squid from MonkMakes.com makes does just that.



The Common Cathode RGB LED squid is terminated in female jumper wires and includes series resistors for the LEDs inside the shrink wrap. So, you can just plug it straight onto the GPIO connector.

Its not so hard making your own Raspberry Squid and you can read just how to do that here where you will find a library that makes it easy to use the Squid.

You can also buy ready-made Squids from Monk Makes in various sets, available on Amazon in the UK and US.



So as well as RGB and Button squids MonkMakes also have a DS18B20, light sensor and buzzers in the pipeline.




Friday, September 25, 2015

The Phobot board and Stepper Motors

The MonkMakes Phobot motor controller board is designed primarily to control a pair of DC motors, to make roving robots that can be controlled over the Internet using the Particle Photon Arduino-ish IoT module. However, you can also use it to drive a bipolar stepper motor.



The stepper motor I used was this 12V motor from Adafruit.

Wire one coil of the stepper (yellow and read wires for my motor) to the M4 screw terminals and the other coil (gray and green) to M3. You will also need a 12V DC power supply wires to screw terminals GND and Vin on the Phobot board.


The Phobot will provide 12V to the stepper motor, but also provide a regulated 5V supply to the Photon, so your Photon's USB port does not need to be connected.

All that remains is to write some code. So log into particle.io and then start a new App. Paste the following code into it:

#include "PhoBot/PhoBot.h"

PhoBot p = PhoBot(12.0, 12.0);

void setup() {
}

void loop() {
    forward(100, 5);
    reverse(100, 5);
}

void forward(int numSteps, int period) {
    for (int i = 0; i < numSteps; i++) {
        p.setMotors("M3-F-100");
        p.setMotors("M4-B-100");
        delay(period);
        p.setMotors("M3-F-100");
        p.setMotors("M4-F-100");
        delay(period);
        p.setMotors("M3-B-50");
        p.setMotors("M4-F-50");
        delay(period);
        p.setMotors("M3-B-50");
        p.setMotors("M4-B-50");
        delay(period);
    }
}

void reverse(int numSteps, int period) {
    for (int i = 0; i < numSteps; i++) {
        p.setMotors("M3-B-100");
        p.setMotors("M4-B-100");
        delay(period);
        p.setMotors("M3-B-100");
        p.setMotors("M4-F-100");
        delay(period);
        p.setMotors("M3-F-50");
        p.setMotors("M4-F-50");
        delay(period);
        p.setMotors("M3-F-50");
        p.setMotors("M4-B-50");
        delay(period);
    }
}

You will also need to add the PhoBot library to the app, by selecting the Libraries button on the Particle IDE and then search for Phobot. Click on the INCLUDE IN APP button to add the library to your new app.



Click on the lightening bolt to deploy the app to your Photon. As soon as the app has finished installing, the motor should start turning, first in one direction and then the other.

Try changing the value of the second parameter to forward and reverse in loop from 5 to 10 and the motor will turn at half the speed. You can also try altering the number of steps (the first parameter).

Note that a period of 5ms is a little fast for this motor, so if you want to avoid steps being missed, it probably needs to be 10ms or more.

You can buy the Phobot board from Seeedstudio Adafruit and also find it on Amazon.com and Amazon.co.uk.

Monday, February 16, 2015

Accurate and Reliable Readings from a TMP36

I have been using the TMP36 for years, with Arduino, BeagleBone and now the Spark Core/Photon. It has often been reported in the Arduino forums that this chip is inaccurate and unreliable. Indeed a quick glance at the datasheet tells you accurate to 2 degrees C (which seems pretty poor).

I'm working on a Spark Core project for a book and tried out a TMP36. The results seemed totally mad, -25C when it should have been 17C. I checked the maths which was all fine. Then, thinking I had a duff TMP36, I connected my multimeter to measure the output of the TMP36. Suddenly the readings started to be accurate and stable! My magic multimeter was making things work right!

So, going back to the datasheet for the TMP36, the equivalent schematic looks like this:

To add a load resistor (I used 1k, but looking at the spec, the load should not really exceed 50uA so a 20k or 47k resistor would be better) to any microcontroller analog input, connect your resistor between Vout and GND on the TMP36.

So, if we have all been using the TMP36 incorrectly for years, then how has it ever worked?

Well, the Arduino has a relatively low input impedance to the analog inputs, so enough current flowed to ground to make it usable, if not terribly good. However the Spark Core has analog inputs that are biased to roughly 1.65V, which totally screws the TMP36 output, without any kind of load resistor. Even my high impedance multimeter voltage range was enough of a pull-down for it all to work.

So, the lesson is:

*** If your TMP36 is misbehaving, put a 47kΩ resistor between Vout and GND on your TMP36. ***