just making

Menu

Some time ago, IBM released a very cool project to the open source community. MQTT or message queue telemetry transport was originally used for communicating with orbiting satellites. Today, MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport and it is useful in practical applications from push notification in mobile Apps to distributed Sensor networks via message brokers.

In this particular project I am using the IBM Really Small Message Broker that supports MQTT, the download has executables for just about every platform out there.. Get it from here

My goal with this project was to create a quick operations console to interface with embedded hardware for messaging and switching. As I am part of an active project called Kivy.orgI figured it would be a perfect tool to provide the user interface for the console. Kivy is a cross platform development framework based on Python and the C language. For further reading I urge you to click over to the http://kivy.orgwebsite and download a copy of the framework for your operating system and run some examples. The API is ultra easy and very feature rich including 2D & 3D support with standard widget libraries and Advanced multitouch gesturing support that all runs in the hardware GPU on Microsoft windows operating systems, Apple Mac OSx operating systems including IOS for the iPhone and iPad as well as support for Android and Linux. The example code I am providing in this blog entry can easily be built simultaneously for each of the above operating systems.

figure 1 – MQTT Topology for Messaging

The 1st step however in the project is to wire the circuit for the MBED Arm Cortex-M3 based system on chip. I chose the MBED for its power however you could equally use and Arduino with an MQTT library (1) to support the same function as the MBED. the MBED contains four pin configurable LEDs that I wanted to link to buttons in the Kivy UI Console, this can easily demonstrate the function of unlocking a door, turning on a fan, or switching on light. Additionally I also want to be able to send messages from the console in human readable text and have them show up on an LCD screen connected to the MBED.

The Kivy.orgcode can be downloaded from http://kivy.org/#downloadas a binary and simply installed, there are a few more steps for IOS and Android App Packaging, links to this documentation can be found in the download page.

Towards the end of school holidays is always a frustrating time for parents. You back at home from the annual trip away and your kids are bored or at least tell you they are bored constantly every hour on the hour. This would be good if you yourself weren’t actually back to work. With my son and daughter constantly in and out of my office my memory recalled a device that create a Youth Repellent Sound.

Upon further study adults have difficulty hearing above the 16 khz range. and for a frequency of 16khz we need a wavelength of 1/16000 = 6.25 10 to the minus 5. Pulse Width Modulation is basically a square wave so we can us it to generate sound.

To fit in with PWM we need to interpret a period to mark the wave high and the duty cycle to 0.5 to get a symmetrical square wave.

#include “mbed.h”

PwmOut speaker(p21);

int main() {
speaker.period_us(62.5);
speaker = 0.5;
}

Schematic

Breadboard

PCB

Code

This displays an LED on the mbed to confirm that the script is running

Some time ago I had nasty smells in my kitchen and no I didn’t leave an egg salad on the table for a few weeks or a bucket of prawns in the sun… The smell was hydrogen sulfide or commonly know as sewer gas. My first step was to get a plumber in to try and trace the issue, it was intermittent and not constant so it was quite difficult to pinpoint. To me it was an issue with the venting of the outside main sewer link into my house but the plumber assured me that the venting was done fine as he worked on the house originally when it was renovated. About once a day, usually in the mornings we got this horrific stink only for a few minutes or so. Not trusting the plumber after all this I decided to look into Gas Sensors and found the Figaro TGS 2602 sensor which does loads of other gasses apart from hydrogen sulfide see data sheet http://www.figarosensor.com/products/2602pdf.pdf. I bought a bunch of these and hooked them up to Arduino UNOs and placed them all over the house. Well believe it or not the first sensor to go off was not in my kitchen but in my attic and as hydrogen sulfide is a heavy gas I was in a quandary. So I had a look inside the roof to attic cavity and lo and behold the vent pipe did not go out onto the roof. This meant that the gas while heavy was going down the wall cavity three flights and under the kitchen floor to the other side of the room. Problem solved, plumber on end of angry phone call….

I threw the design into Fritzing to share to all for the next time your plumber is a lazy #*^%$# and won’t look in the roof.

// The address of the server you want to connect to (pachube.com):
byte server[] = {
173,203,98,29 };

// initialize the library instance:
Client client(server, 80);

long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const int postingInterval = 10000; //delay between updates to Pachube.com

// if there’s incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// if there’s no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
}

// if you’re not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() – lastConnectionTime > postingInterval)) {
sendData(sensorReading);
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}

Just received a Bus Pirate from Coolcomponents.co.uk, its the Sparkfun Bus Pirate with their ribbon cable and not the Seeedstudio (Dangerous Prototypes) so be prepared to reverse the order of the colour pin outs. This was my first point of confusion in that the Firmware menu nicely identifies the pin outs for the colour ribbon cable but these are back to front on the Sparkfun device and ribbon cable.

Don’t follow the output from the v command above for colour alignment, the below chart is for the ribbon cable for the Sparkfun Bus Pirate so GND is not Brown it is Black(which is bleeding obvious for normal conventions). Work your way across from black for the Voltage values i.e. it should really be 1.(Blk) 2.(WT) 3.(GR) etc..

The Blinkm uses I2C as a communications protocol so we need to use the black and white wires on the PWR -(GND) and +(3v) pins and the yellow and orange wires on the c(CLK) and d(MOSI) pins. In addition you need to have voltage applied to the pull up resistors (VPU) which is the blue wire. The Sparkfun ribbon doesn’t come with probes so I borrowed one from my Saleae Logic Analyser http://www.saleae.com/logic/ .

I2C is an open-collector bus, it requires pull-up resistors to hold the clock and data lines high and create the data ‘1’. I2C parts don’t output high, they only pull low, without pull-up resistors there can never be a ‘1’.
So to get the pullup resistors to high issue a capital ‘P’.I2C>PPull-up resistors ON
To save time you can issue a ‘WP’ to turn on the power and raise the pull up resistor.I2C>PWYou should now have the power on and the pull up resistors on, to check this issue an ‘i’ again.

Notice that the voltages have changed on the pins and that power and pull-ups is ON.
Here is where I’m going to help you cheat a bit, normally we would run a macro I2C>(1) or enter (1) at the prompt, this sniffs the available addresses for you but for now lets get straight to issuing a few commands against the Blinkm.

The default Blinkm script is still running so we need to stop it.
[0x00 “o”] stop the running script on the Blinkm

The Blinkm default script should now be off and the led will be lit at the colour the script happened to be in when we issued the stop command. In the image below I stopped it when it was in the off cycle.

The Blinkm address is 7-bit plus one bit for R/W. Blinkm 0x09 is 0x12 for writing and 0x13 for reading.

I am using an Arduino UNO so SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5.
There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it’s being written to or read from. The Wire library uses 7 bit addresses throughout and so does the Blinkm so for an Arduino sketch we can use 0x09.