Tuesday, April 7, 2015

20140611 SKYNET.IM

UPDATE: I think this project is gone, and has become something else skynet.im doesn't work any more (2015-Apr-7) So this listed for historical reasons!

20140611 SKYNET.IM
Yup, the terminators are coming, Chris Matthieu along with a few others have been working on machine to machine messaging.  I’ve been giving Chris a hard time about the robots coming back, he is making it happen!!! Seriously thou, Skynet is a fairly easy to use set of protocols for talking to any machine. Chris has (and I think mistakenly) said you don’t need a CPU - What I think he means is you don’t need a desktop/laptop full sized computer (or for that matter a rPI, BeagleBone, or small computer) You do need a processor of some type - A microcontroller works well.
So what is Skynet? In a nutshell it’s a simple way for machines to talk to each other.
It takes the Firmata protocols and builds on them to be used over wireless or ethernet.
SO what is Firmata? It’s a generic protocol for communicating with microcontrollers from software on a host computer. http://firmata.org
I haven’t gotten into the firmata implitations of skynet yet, and that maybe something for a later meeting.
With Skynet, every machine generates it’s own UUID and API codes, they can be overwritten if you need to.  The programs/api use these UUID and codes to talk to each other. You can name them, but the machines will still use the UUID.  
Going to verify this at the library, but it seems once connected, the machines UUID stay with them, making it easy on us humans, and at least easy enough that we don’t have to change our code everytime we plug in the device.

There is a web impliation of skynet using google chrome and something called NodeBlu which is based from something called NodeRed.
NodeBlu, is a connector, it really is easy to pull blocks down and connect them to other blocks to have a remote device do something.

But the real power of skynet comes from the API, using simple restFUL commands, someone can control the remote device from the command line.  OR Two skynet connected devices can connect to each other and decide what to do.
Chris has a number of videos on Skynet, https://www.youtube.com/channel/UCBMdqdAbjJjE9LvMjVpiwUw
I was watching a few of his videos to get ideas on what to demo, and came across one where he could call (on his phone) his connected devices - this is very cool when it comes to automation. Think about it, if I could call Skynet, say “I’ll be home in 10 minutes unlock the door” and I had a door that could be remotely unlocked, in 10 minutes the door would open.  Using that same idea you could text your home and ask for a status update.  All very easy to do.

So My demo is going to be on the “Echo” sketch that is included with the Skynet-Arduino-Firmware Library Created by Jacob Rosenthal https://github.com/skynetim/skynet_firmware_arduino
Jacob also has several other skynet librarys in his “skynet” github https://github.com/skynetim
Another developer/contributor to Skynet is Luis Montes (monteslu)- He has worked on the Skynet Firmata  and he has some librarys on github as well. https://github.com/monteslu
I can tell you that I’ve “spoke” well chatted with all three of these people over the past couple of weeks and all are very knowledgable and helpful on skynet and how it works.
In fact a few of the issues I had at first with NodeBlu Luis said he could fix or try to fix so it was a little more clear as to what is needed.

But wait I was talking about my demo - It’s the “Echo” sketch, and at first it wasn’t clear to me what this sketch did.  BUT Simply if you send a message to it, it will “Echo” that message back to you.

Using NodeBlu, I was able to setup something that I could either speak to it, google would use it’s speech to text engine and send the message on to the machine (arduino), a couple of seconds later the arduino would send back the text and google would use the text to speech engine and speak what I said.  Yes, I know, all of that could have been done quickly and easier with sending the text to the machine, but it’s a demo of what can be done.  This is using the stock “Echo” sketch and a NodeBlu program that I built.
I can also just type a message into the NodeBlu program and that will get sent to the arduino, and come back and speak.

My 2nd demo of Skynet, I have hooked up a DS1620 temperature sensor (Which seems off to me today it’s saying it’s 82 degrees in here, seems high, maybe because the library was written for a UNO and I’m using it on a mega) doesn’t matter, it’s a concept. I’m using the same NodeBlu program, but this time, anything I say, or ask for it will speak the temperature to me.

So you might be looking at the NodeBlu program above and wondering what is going on?
There are two parts to this, (maybe three), the first step is to setup your remote devices,  Called NODES - You can name these devices anything you want, the name isn’t important as it’s for us humans anyways. But you will need the device UUID and the Token (on the Arduino you can get both these from the serial monitor)
Next you drag some blocks over to the workspace - most of the blocks are self explanatory as to what they do, some are inputs and some are outputs, and some are both. (So if the connector is on the right side it’s an input, if it’s on the left side it’s an output, and on both sides well it’s both) There are two blocks that aren’t so self explanatory, they are the Function block, and the switch block. So the function block will allow you to write some Java script functions that can change the course of the program on the NodeBlu side of things.
Remember it’s looking for JAVA - which is a little different, and threw me for a bit as too way things weren’t working.  Right now there is nothing that tells you there is an error, and this one of the things that Luis thought he could fix. The switch block is an kind of like a IF statement block, you can add multiply paths for the output to go to.  In my example you can see 5 different directions the output can go.  

So that is just briefly what Skynet is, and what it can do, The unfortunate part is the guys that created this are programmers by profession, and they didn’t do such a good job in my opinion documenting things, And for someone who is just starting programming, or someone who has never used a API this might be a real struggle.  I have used APIs and been programming for a while now and I found at least parts of it to be confusing, I’d consider myself to be an intermediate level programmer, nothing these guys can do.  It’s an old problem with us programer types - we understand and know how it works, and don’t think about what the end user knows or the skill level they might be at.  Happens all the time. The best thing I can say is the guys on Chris’s team are very knowledgable, and do understand what is going on, and are very helpful. (Twitter is probably the best way to get them, I know that Chris watches both Twitter and G+ most of the day)

Release the Robots!

Modified Skynet.im Echo sketch to include DS1620 Temp Sensor:
*
*                SSSSS  kk                            tt    
*               SS      kk  kk yy   yy nn nnn    eee  tt    
*                SSSSS  kkkkk  yy   yy nnn  nn ee   e tttt  
*                    SS kk kk   yyyyyy nn   nn eeeee  tt    
*                SSSSS  kk  kk      yy nn   nn  eeeee  tttt
*                               yyyyy                       
*
* SkynetClient for http://skynet.im, OPEN COMMUNICATIONS NETWORK & API FOR
* THE INTERNET OF THINGS.
*
* This sketch parses any messages it receives and echos them back to the
* sender.
*
* Works with ethernet shields compatible with EthernetClient library from
* Arduino. If you don't know, grab the original
* http://arduino.cc/en/Main/ArduinoEthernetShield
*
* Also requires the ArduinoJsonParser
* https://github.com/bblanchon/ArduinoJsonParser
*
* You will notice we're using F() in Serial.print which might be new to you
* Its covered briefly on the arduino print page but it means we can store
* our strings in flash, instead of in ram.
*
* You can turn on debugging within SkynetClient.h by uncommenting
* #define SKYNETCLIENT_DEBUG
*/

#include <EEPROM.h>
#include "Ethernet.h"
#include "SPI.h"
#include "SkynetClient.h"
#include <JsonParser.h>
#include <DS1620.h>
#include <stdlib.h>

EthernetClient client;

SkynetClient skynetclient(client);

//you can't have 2 of the same mac on your network!
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char hostname[] = "skynet.im";
int port = 80;

static const uint8_t RST_PIN = 7;
static const uint8_t CLK_PIN = 8;
static const uint8_t DQ_PIN = 9;

DS1620 ds1620(RST_PIN, CLK_PIN, DQ_PIN);


void setup()
{
 pinMode(8, OUTPUT);
 Serial.begin(9600);
 delay(100);
 ds1620.config();
 // start the Ethernet connection:
 if (Ethernet.begin(mac) == 0) {
    Serial.println(F("Failed to configure Ethernet using DHCP"));
    // no point in carrying on, so do nothing forevermore:
    for(;;)
     ;
 }
 skynetclient.setMessageDelegate(onMessage);
}

void onMessage(const char * const data) {
 JsonParser<16> parser;

 //Serial.print("Parse ");
 //Serial.println(data);

 JsonHashTable hashTable = parser.parseHashTable((char*)data);

 if (!hashTable.success())
 {
     Serial.println("JsonParser.parseHashTable() failed");
     return;
 }
   
 char* payload = hashTable.getString("payload");
 //Serial.print("payload=");
 Serial.println(payload);
   
 char* fromUuid = hashTable.getString("fromUuid");
 //Serial.print("fromUuid=");
 //Serial.println(fromUuid);


 const float temp_c = ds1620.temp_c();
 const float temp_f = temp_c * 9/5.0 + 32;

 Serial.print(temp_f, 1);  // 1 decimal place
 Serial.print("F ");
 Serial.print(temp_c, 1);
 Serial.println("C");

 String s = dtostrf(temp_f, 1, 2, payload);
 skynetclient.sendMessage(fromUuid, payload);
}


void loop() {
 while(!skynetclient.monitor()){
   
    bool skynetStatus = false;
    do {
     skynetStatus = skynetclient.connect(hostname, port);
    } while (!skynetStatus);
   
    Serial.println(F("Connected!"));
   
    char uuid[UUIDSIZE];
    skynetclient.getUuid(uuid);
    Serial.print(F("uuid: "));
    Serial.println(uuid);
   
    skynetclient.getToken(uuid);
    Serial.print(F("token: "));
    Serial.println(uuid);   
 }
}

So you’ll see it doesn’t matter what you send to it, it will send the temperature back everytime - you can be really impressive thou and say “What is the Temerature” to fool people.
Simple prove of concept sketch, and a good demo

UPDATE: I think this project is gone, and has become something else skynet.im doesn't work any more (2015-Apr-7) So this listed for historical reasons!

20140626 Make your own FTDI cable (CHEAP)

20140626 Make your own FTDI cable (CHEAP)
I needed a extra FTDI cable, and I did find a cheap FTDI from China awhile ago, I think it was 7 bucks, about half of what everone else wants for a “real” FTDI. But I really don’t want to spend even this much for a FTDI.
This cable will cost about $3.50 but does require some work to make.
http://letsmakerobots.com/node/23728 It uses a CA-42 USB2.0 Nokia Data Cable, Seems like a lot of things for the old Nokia phones will work with our micro-controllers.  The link explains what you need to do, but in short, unsolder the wires that are on the chip, put 6 new wires on it, and solder pins to the end. And you have a DIY-FTDI cable for right around $3.50.
Drivers: Linux should have the drivers built in. For Windows you might need this:
Thou there is some debate on the website as to if this is the correct driver for the cable, you may have to hunt, but the drivers should be able to be found.
The best place to find the cable now is eBay:

IF making your own cable is not your thing then take a look at this:
FV88 FT232RL USB To Serial Adapter Module USB TO 232 Download Cable For Arduino
This is the chip that the FTDI is based on, I haven’t tried it yet, but looking at the pin-out of the chip it matches up to my $7 dollar FTDI, The biggest difference it seems this has male header pins, and most FTDI have female header pins, it’s even got a switch for 3v and 5v. Coming from China of course, but this seems to be the closest I’ve seen to a true low cost FTDI, order one and waiting. Cost $3.50, no work, unless you want to change the header out.

20140620 Doppler Radar Speed Detection using an HB100 10.525ghz radar gun.

20140620 Doppler Radar Speed Detection using an HB100 10.525ghz radar gun.

(I’ve updated this to a new library with better results, see below)

The HB100 is a 10.525Ghz radar gun, normally found in automatic door openers. But it can be used for other things.  
For most of the information I used to finally get this to work, I referred to the “Microwave Sensor Application Notes”
It contains all the information, radiation data, and circuit to amplify the output single.
The HB100 has an IF output frequency that is or should between 10hz and (say) 400hz.

It gives the formula to figure out Doppler frequency, which is
Fd = 2V(Ft/c)COS theta
Fd = Doppler Frequency, V = Velocity of the target, Ft = Transmit Frequency, c = speed of light (3 * 10^8 msec)
theta = the angle between the target moving direction adn the axis of the module.

IF the target is moving straight toward or away from HB100 (Ft = 10.525 Ghz) the formula is simplified to:
    Fd = 19.49V (Velocity in km/hour) or 31.36V (V in mile per hour)

So we are going to use the simplest of the two, we know the doppler frequency, and we want to find the speed.  
V = Fd/31.36 … What this really means thou, is for ever 31.36Hz will equal 1 MPH
So if the IF Frequency is 31.36 then the speed of the target is 1 MPH. Easy!

And a IF Frequency of say 400Hz would be about 13Mph if you round it up.

This was made even easier to find the frequency of the IF because I found a sketch that was a Frequency counter of sorts, and after the amplifier was built, I started to get some good speeds off the radar.
The FreqMeasure Library can be found here:
This was a hugh time saver, and it works very well.
You do have to approach the gun from head on, but it works and does a good job, and give speeds that I believe are very close to being right.  Over the next day or so I’ll try to get out on the road and see if I can get some real speed tests.
Video will be posted shortly.

Updated May 23, 2014: A new library and better results:
Found the above library from a link on the prjc website, this is apparently the library he based his library off of. What is interesting is I think I am getting better results from the original work then I was from the prjc libraries.
A couple of things, the library seems to be using 3 pins for input, and a couple of resistors,  but I found that with this doppler setup really only one pin was needed (as it was before) however it’s pin 7, a resistor doesn’t appear to be needed.  The library doesn’t have any “examples” to speak of, and the code that is on the site contains many errors (Yup, I spotted a lot of errors before I even got started)  I am thinking the code was written in pure C and the library was written for the arduino (maybe even an old version of the IDE)  It hasn’t been updated since 2012.

SO the code I came up with:

#include “FreqPeriod.h”

double lfrq;
long int pp;

void setup() {
Serial.begin(9600);
    FreqPeriod::begin();
    Serial.println(“FreqPeriod Library Test”);
}

void loop() {
    pp = FreqPeriod::getPeriod();
    if (pp) {
        Serial.print (“period: “);
        Serial.print(pp);
        Serial.print(“ 1/16us / frequency: “);

    lfrq = 16000400.0 /pp;
    Serial.print(lfrq);
    Serial.print(“ Hz “);
    Serial.print(lfrq/31.36);
    Serial.println( “ Mph “);
}
}

This library is a lot faster then the FreqMeasure library (which seems to be taking an avg over a period of time and giving back a freq.) This one seems to just spit out freqs. So it seems like it’s a lot more sensitive to changes.  In fact as I approve the  doppler even from the back side of it, I get a change on the screen.  Good/Bad??? I’m not sure of the answer.
The speeds seem much more reasonable as well, and perhaps that is the math using the double integer, perhaps that is the fact that I am dividing the HZ / 31.36 (which is the real number to use)

Thou, I have notice that using this Doppler Gun, and the fact that it is not very directional is a problem for doing any real speeds off it.

The other thing to note is that with this library my range seems to have increased, I am thinking this might be because it’s not trying to take an average and is just spitting numbers out as things change.

I am going to do a new video with the updated library.

20140525 - Hot Wheels 10.525ghz radar gun - Update #2

20140525 - Hot Wheels 10.525ghz radar gun - Update #2
The above website takes apart one of the Hot Wheels radar guns, and has some great pictures of the components. Something that you might notice is that the gun itself is very much like the little gun we have.  The biggest difference is it’s in a waveguide that helps to direct where the radar signal goes. But otherwise it is very much like what we have.  
One other thing you’ll notice is that he also had to add an amplifier to get a signal he could use, I believe that there is an amp on the “control board” but it may not have been easy to access that.
You’ll also note that his IF is also in the 10Hz to 150Hz range, which makes believe the hot wheels gun is using the HB100 or at least something that is very close to it.

There are quite a few projects that are using the Hot Wheels gun, including a Weather Radar (well sort of),
Does make me wonder if we could use what we have an mirror the above project, looks like it might be a big project.
And here’s someone that “made” a speed gun out of the Hot Wheels radar gun (What, this is already a speed gun???)

To make a real gun, we need more power which we are limited to using this unit. But we might beable to focus the waves better using something like this: It’s a 10ghz (X-band) radar cone, it’s tuned for the X-Band, and will direct the waves much better.  This is very much like what is in a commercial radar gun (IF the cops were still using X-Band)
It’s still not going to be perfect, not with this unit, but it will be better.

I would like to try to tune the gun, but for that we need tuning forks (Any should work, I think) as long as we know at what Hz they vibrate. (IE: a fork vibrating at 200Hz should be about 6.3 or 6.4 MPHs  Hz/31.36 = MPH) Short of having any tuning forks there is no sure way to know that what we are doing is working correctly or not.  

One Idea I have is to roll a hot wheels car, see what the hot wheels guns says, and then roll it again and see what our gun says. Hopefully they will be the same or close to the same - But that method has a problem that is the push was a little more or a little less then results would be a little different.  

SO if anyone has any tuning forks that we know the vibration of bring them to this Thursdays meeting and we will see if we can figure out!

20140519 2.4” TFT touch screen Arduino Shield

20140519 2.4” TFT touch screen Arduino Shield
The TFT touch screen arrived today, and I literally spent hours looking for the right library. I did find a library called “UTFT” or should I say an extension of “UTFT” that someone fixed, UTFT plus can be found here:
I found that using the “Uno” sketch included did work with the screen, I couldn’t get the touch screen or the SD reader working using this library.  And the sketch printed the letter backwards, like how it would look in a mirror.  So it was a start, but it’s not the right library for this display.

Finally I came across this video:
and they gave a link to some weird website that does have English, but it’s not the native language...very weird site:
Well sometimes you just have to put up with the weird sites. Found a library that WORKS! I did have to make a couple of small changes to the font library (been seeing this error a lot lately, not sure why, but the error tells me that something in the .h file needs to be setup as a const) So it’s a pretty easy fix.

At this point I still haven’t seen how to make the SD card reader work, but I’m ok with that. The library has two sketches, one is a touch screen paint program, and the other is just a long demo.

I’ll have a video posted in the next day or so, and I’ll also beable to see if or what it takes to make my own demo of the screen.


UPDATE: I put a library that does work with this screen in my google drive,
It was made for a older version of the IDE, gives an error but is an easy fix (off the top of my head I can't remember what that error is, or where it is at.  It is in one of the .cpp or .h files) It maybe the same error I talk about above.
https://drive.google.com/open?id=0B7GpAH3_kkRLSEk2Wm9HdGNGYTQ&authuser=0

20140513 - PWM Speech using an UNO

20140513 - PWM Speech using an UNO
So after playing around with the SID library, I thought what about speech? Well turns out, I’m not the only one to think of it, the the libraries were a little hard to find, because the one that everyone talks about is very out dated, and doesn’t work with any of the Arduino 1+ IDEs.
Even the one I finally found had a couple of small errors in it, but fixed almost all of the bugs from the original library.
It can be found here: https://github.com/jscrane/TTS
One thing that I had to fix was an error in the english.h file found in the TTS directory. The SoundData variable needs to be declared as a const, it was an easy fix. I did leave a message on github for the author of the library.
This library is based on what Clive Webster did, and was ported by Gabriel Petrut. And Stephen Crane modified it more so you can change what PWM pin it uses (a very nice feature to be sure).  So anyways, it’s a pretty simple library, set which pin you want to use.
the other commands as far as I can tell are.
setPitch, and sayText
It uses Timer1 to generate the PWM, and you need an amplified speaker with a good filter - mine works, but the filter probably could be better.
Video will be posted shortly, but this sounds very much like my SpeechJet/Robovoice chip (which was/is also using PWM to generate the speech.) The Robovoice chip is a PIC microcontroller, and has all the phonemes pre-programmed on it.  The arduino uses the english.h file for it’s phonemes,  and I think there maybe an error or two in a couple of the phonemes, but I can’t say for sure.
Anyways, video is coming.

May 11, 2014 - SID Arduino Library
Today while looking for some interesting projects, I stumbled upon.
https://code.google.com/p/sid-arduino-lib/ It looks like it might be abandoned project, but there is enough there to get going.
So this is really simple to hook up, PIN 9 to one side of a speaker, and ground to the other side of the speaker. I used one of my little speakers out of a old Dell computer so it was amplified, and needed to be connected to 3v, no big deal.
Figuring out some of how the sketches worked was a slightly different problem, but after I figured out one song, it was fairly easy to create others.  The library can handle up to three “Channels” or “voices” thou I haven’t figured out if each channel can have a different waveform, like the C-64 could. And getting some of the timing issues right were a little weird.  In fact the timing really kind of had the opposite effect as what was expected. And what I found out was that there is a type of sustain and decade on the waveforms, and that ended up being the trick to get some music working, I would need to hit a note, wait (delay) and then tell it to or force it to play freq 0.00 which can’t be heard, thou on one of the songs I did I did get some clicks, not a big deal.  
So I have a video coming, but it might not get done this week.  Overall thou, this was one of those quick and fun projects, that didn’t really need anything other then a board and speaker to work. 



20140508 BMP180 Digital Barometric Pressure Sensor

May 8, 2014
BMP180 Digital Barometric Pressure Sensor
Once again the folks over at Sparkfun out do the folks at Ada Fruit - Starting to worry about the people at Ada Fruit they are slipping alittle.  LOL
There is more information about this sensor then I could possibly give you, they even go into what pascal are (Pa, Basicly it’s a measure of force per unit area, defined as one newton per square metre - You get all that...yeah, see Sparkfun explains it beter)
The device that Sparkfun has is different, from what the club has, but it’s almost the same, it’s close enough that their tutorial works really well.  The sensor on it is the same sensor that on the clubs BMP180.
The device is an I2C device, it is very easy to hook up. SDA, SCL (Data and Clock), 3.3v and ground, that is it.  On the UNO it’s SDA to A4, SCL to A5
The other VCC connector on the board is for voltages lower then 3.3v



alt text
Ada Fruit does have plenty of information about this sensor as well, and their sensor looks more like what the club has.

The problem I had with Adafruits was the sketch didn’t seem to give as much or as good information as what Sparkfun did.
weather_bmp085_bb.png

Adafruits also requires one extra library which wasn’t included in the download package provided, that caused an issue for about 2 mins until I realized it called a different library.  Not sure why they did that, but after I got the 2nd library it did work, just didn’t seem as good as Sparkfun.
The outputs from the sensor, are Pressure, Temperature, and Altitude (Altitude can be both above sea-level and as a relative from it’s starting point), this is a very cool sensor, and with the addition of the humitdy sensor and maybe a wind speed sensor, this could be a complete low cost weather station. 

 https://www.sparkfun.com/tutorials/253