---

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. ***

Thursday, July 17, 2014

Raspberry Pi Model B+ Review

CPC very kindly sent me a Raspberry Pi model B+ to try out.

As you can see, there are a few changes when you compare it to the Raspberry Pi Model B in the middle and the model A on the right. This board is a pretty serious upgrade to the Model B while still being very affordable at just £22.87 + VAT (about $40).

Raspberry Pi, models B+, B and A

The most obvious change is that there are now four USB ports rather than the two of the Model B. This is a great improvement and removes the need to have a USB hub connected to the Pi. It means you can have a keyboard, mouse, USB WiFi dongle connected and still have a spare slot for a USB pen drive.

I think that the provision of four USB ports is extremely significant, because it marks out the Raspberry Pi firmly as a real computer and not just another tiny Linux board designed to be used as an embedded controller.

This brings me on to another obvious change. The GPIO port has grown from 2 rows of 13 pins to 2 rows of 20 pins. Many people will never use the GPIO port on a Raspberry Pi, content to just use it as a computer. But if you want to use your Raspberry Pi to control electronics, you now have some more pins to do it with. The additional pins are at one end of the board to maintain compatibility with existing add-on boards.

Another change is the removal of the little-used composite video socket. This allowed you to attach AV monitors of the type used in CCTV to the Raspberry Pi. This connection is still available but supplied as an extra connection on the Audio jack, which is now an AV jack, combining both audio and video.

There are other changes, both cosmetic and improvements to the design.
  • The corners of the PCB are rounded off, which makes it look a bit sleeker and more professional. Not that that makes a blind bit of difference really.
  • Of more significance are new mounting holes arranged in a rectangle, rather than at random locations on the board.
  • The sockets aren't all in the same place (so you'll need a new case)
  • The power supply is now reverse polarity protected and the linear voltage regulators (which get hot) have been replaced by switching regulators (which don't).

Does it Work?
All in all, all these improvements are very welcome. I think that the Raspberry Pi foundation have hit the nail firmly on the head with this update. But of course the million dollar question for all of us who have model B boards is 'will our stuff work?'

Since I was using a full-sized SD card in my model B, I obviously could not just use the same SD card. Even if you are using a micro SD card in an adapter on a model B, you will still need to upgrade Raspbian to the latest version using a model B before moving the SD card over to to the B+. This is because the B+ uses a different Ethernet controller chip.

When setting up a Pi, I prefer to create a full Raspbian iso disk image using Pi Filler rather than use Noobs. This is because I generally use my Pi through SSH and VNC rather than attach keyboard, mouse and monitor. Noobs needs a keyboard mouse and monitor.

So, I created a micro SD card using the 2014-06-20 distribution of Raspbian. The Pi looked happy until I tried to ssh to it. No response. So, I plugged keyboard, mouse and monitor in, and rebooted. It did boot, but with a load of errors and then failed to run raspi-config.

Now that I had the Pi all accessorised, I thought I might as well try the latest Noobs and this worked perfectly, first time.

Lesson - if upgrading from a B, copy the stuff you need off to a flash drive, then run Noobs on a new micro SD card.

Next, I though I should try out the GPIO connector, so I put together the Charlieplex LED project from the Raspberry Pi Cookbook.



This all worked fine.

I also thought I had better check out the RasPiRobotBoard V2 and make sure that all was well with that. It was, so all in all no compatibility problems so far.

Next, I thought I had better test out I2C, so I plugged an Adafruit LED Backpack into the I2C socket of the RasPiRobotBoard, loaded up the Adafruit example code and everything worked just fine.



I didn't try out any of the new GPIO pins, but I have no reason to doubt them. You can find a pinout for them here. My next job is to update the Raspberry Leaf and make a B+ version.

Conclusion
I love this board. There's nothing wrong with the plain model B, but this positions the Raspberry Pi as the undisputed ruler of the Single Board Computer.


Books.
You may be interested in the books I have written about the Raspberry Pi.


Thursday, June 19, 2014

Raspberry Pi Battery Power

The Raspberry Pi uses a pretty modest amount of electricity and it is perfectly possible to run in for short periods using batteries. In this post, I will look at some of the options for making your Pi run on batteries.



How Long Will the Battery Last

Whatever technology you use to battery power your Raspberry Pi, there is one key figure for the battery that you use that will determine how long you will get. This is the battery capacity in mAh (milliamp hours). So, if a battery describes itself as 1000mAh, then it can supply 1000mA for one hour before they go flat. This is an approximation so you may get more or less time.

Now, a Raspberry Pi without anything at all attached to it (no keyboard, mouse, display or WiFi dongle) will use about 400mA. Attach WiFi and a couple of peripherals and this will typically jump to about 600 mA or more. This will actually fluctuate quite a lot, depending on how busy the Pi is. So, driving video, or running a complex program will increase the power even more.

If are pessimistic and assume that the Pi will use 800mA, then we can expect about 1000 / 800 = 1.25 hours of operation from a 1000mA battery. Double the battery capacity to 2000mAh and we should get twice as long.


Battery Booster

The first and simplest option is to use a USB backup battery designed to give the battery of a smartphone a boost. You can see the battery plugged in an charging below.



These batteries actually include not just high capacity light weight Lithium Polymer (LiPo) cells, but also a charging circuit and switch mode voltage regulator. The charging circuit comes into operation when the battery pack is plugged into a USB socket on a power supply or your computer. This charges up the cells ready for use.

When you are ready to power your Raspberry Pi with one of these, you unplug it from its USB power supply and swap the lead over so that it is now providing power to the Raspberry Pi through its micro-USB lead (see below).



These devices can be bought on eBay or Amazon very cheaply and at a variety of different capacities. If you are going to use WiFi on your Raspberry Pi, then you will need to look for one that can supply 1A (1000 mA). Be aware, that many of these are only rated at 500mA. You may be lucky and this may be able to keep up with the demands of a Raspberry Pi with WiFi dongle, but then again, it may just crash unexpectedly or just die. So for a little bit extra look for one that will supply 1000mA.



LiPo Racing Pack

R/C vehicles use high capacity LiPo battery packs. These can also be used with your Raspberry Pi.



Unlike "battery boosters" these batteries do not have built-in chargers or voltage regulators. You will need to provide both these features separately, in the form of a battery charger and a switching voltage regulator circuit such as that found on the RaspiRobotBoard v2 (RRB2) from MonkMakes. The RRB2 actual provides other features such controlling motors, so if you are making a robot, then this may be a good option.

Racing packs suitable for the RRB2 should be of the two cell (7.4V variety). Having charged the battery you can connect it to the screw terminals on the RRB2 that will then provide all the power that the Raspberry Pi could need (up to 2000mA of current, with peaks of 3000mA).

A racing pack will generally have one set of leads for charging and a different pair of thicker wires for powering things from. A pair of male to male header wires will neatly connect the battery pack to the RRB2.

This approach is great if you are making a robot, because the RRB takes power for the motors straight from the battery.


AA Battery Pack

As well as using a RRB2 with a LiPo racing pack, it will also work just fine with an AA battery pack. You will need six cells, especially if you are using rechargeable batteries, which are a slightly lower voltage than alkaline cells.



The battery box is attached to the screw terminals of the RRBs just like the racing pack.

A set of fresh AA batteries will typically provide about 2000mAh.

Conclusion

If you just want to power the Pi on its own from batteries without making a robot, then the battery booster is the best option. However, if you are planning to control a motor or need some of the other features of the RRB2 such as using 5V I2C displays then the RRB2 with either an AA battery pack or LiPo racing pack is a good approach.



Books.
You may be interested in the books I have written about the Raspberry Pi.



Monday, June 9, 2014

TI Programmable 57 Calculator Battery Conversion

As a teenager, I had one of these calculators and I recently came across a non-functional one advertised on eBay and couldn't resist.


These calculators used a strange battery pack that had two NiCd AA cells, along with a buck-boost chip to raise the voltage to 9V. Of course 30+ years on and in most cases these batteries leak and destroy the buck-boost PCB. 

Fortunately its pretty easy to replace the NiCd pack with a PP3 9V battery.

To make this adaptation, you will need a PP3 9V battery clip and a 3 pin 0.1 inch header strip. Solder this up as shown below, with no connection to the middle pin.

Next, you will need to disassemble the battery box. Be careful with this, if the batteries have leaked you will find nasty stuff in there. Once its apart, clean it really thoroughly and dispose of the corroded innards properly.

Unplug the three way socket from the battery pack. This is what we will be connecting to the lead we have made.

IMPORTANT: ON THE TI-59 CONNECTOR, THE RED LEAD IS NEGATIVE AND THE BLACK LEAD POSITIVE.

Although it feels completely wrong, you need to connect the red lead of your battery clip to the black lead of the calculator's connector, as shown below:




I took my calculator case apart (I wanted to see what was inside). You probably don't need to do this, just to do the battery mod.

Finally, fit everything back together again. Getting the battery in just the right place for the back to fit on is a little tricky, but it will fit.


Fit the back of the battery box onto the back of the calculator and you are done!

One of the things that attracted me to this calculator is that as a teenager, this was one of my first experiences of programming. The Wikipedia page for the TI-57 is very informative and also has an example program to run (dice).

You can also find the manual for the calculator as PDF online.