IP Cameras

July 11, 2013

So… I finally purchased an Ip Camera, courtesy of the cheapest eBay listing I could find.

It’s a Foscam FI9818W. Pan and Tilt, wired and wireless networking, 2 way audio and Infared illumination. Pretty slick for $45. If only it had relay outputs.


So I plugged it in and got it talking to my network. Here it is looking at the wall.


 I also got it working with the Foscam App for iOS. 2-way audio built in!



Firmware is a bit old… Lets update that.

It also has motion detection and can automatically email photos or upload them to an FTP server.

I set it to email me a few snapshots when it detects motion outside of the regular business day.



Hi

Wave for Mr Blurry Cam!


This post was composed and uploaded from Microsoft OneNote 2013 
Leave a Comment

Nanode Round 3: SketchGarden

March 17, 2012

Speaking of clouds, Sketchgarden.co finally launched in Beta (as of 3-13-2012), allowing the remote upload of Arduino sketches over the internet. As I have already have a working specimen running on my Nanode v5 hardware, I popped in the new atmega328 chip, and it couldn’t have been a simpler process.

This have been a long time coming. In my prior post covering the build of the v5 nanode kit, I included details regarding possible remote firmware uploads and tftp bootloaders. Sketchgarden surpassed my expectations by eliminating the requirement for a server or  any server side configuration. I only need to worry about configuring my code. Minimal hardware is also a big advantage- they were able to fit the code for everything into the Atmel328p chip in flash and eeprom, aside from the external eeprom used to store a permanent  MAC address. (picture)

There are two elements that will be required for widespread adoption – Number one, the release of the bootloader. On twitter, Vic indicated a post-Makerfaire release of the bootloader in a finalized form. In the meantime they plan on shipping pre-loaded chips from wickeddevice.com.

The next element required to get the ball rolling is compatibility with both ENCJ and Wiznet ethernet modules. The Nanode uses the Microchip ENC28J60, while the official Ethernet shield and the Arduino Ethernet use the Wiznet W5100 chip. Both chips are also available as ethernet shields. Support for both chips will enable non-nanode customers to utilize sketchgarden, enabling WickedDevice to reach a critical mass. Boom.

The WickedDevice Nanode V5 is available assembled($49)or as a kit ($39, includes FTDI adapter). The Sketchgarden chip comes preloaded with the custom Sketchgarden bootloader, but is currently listed as unavailable,-It may not be offered for sale until the initial beta is complete.

A big thanks to Vic and Dirk at Wicked Device. You can find out more information at WickedDevice.com, or check out Vic and Dirk on Twitter. You can also check out their blog.

 

ON TO THE GOODS 

I went ahead and documented the process, including specifics for OSx users:

In a nutshell: Install new Chip, configure network settings locally, set up new nanode on sketchgarden.co, Compile hex file and convert to a binary image. Then upload image and assign to your device. Boom. Done.

 

#1. Install New Chip (available soon at wickeddevice)

chip swap

You should use caution when removing microchips… 

#2 Connect to your device on your local network, and change the settings to fit your network as necessary. The settings will be stored to the atmel328 eeprom and will remain static until changed.

Note: The sketch  seen below is called “SketchGarden Config” to re-load on your device should you need to re-configure your IP address, should you decide not to incorporate 

This is the pre-loaded Sketchgarden Config Sketch. It will be replaced with your sketch on first upload. Don’t forget the copy down your API key from this screen.

#3 Connect your twitter account at  sketchgarden.co

You don’t have to tweet, but you gotta have a twitter.

#4 Add your device with the Api key you obtained before.

 

 

#5 Compiling your working Nanode/Arduino sketch to hex:
Go to your working arduino / Nanode sketch. Hold down the Shift key and click the > compile button. Look at the last section and identify the file path. If you are cool like me, and have OSX, your files will be hidden in some folder that you can’t see.

/var/folders/ blablabla

That’s ok, here is a shortcut for OSX users. From finder, select Go, then Go To Folder, then paste in your long folder location.

complicated eh?

For me it was /var/folders/RZ/RZv65MxvH4GoCj14HxLTjk+++TI/-Tmp-/build654337670699641674.tmp/  sketchname.cpp.hex

 

locate your file and copy it somewhere you can see it.

organized files? I think not.

Now convert  the hex file to a bin file using the tool from sketchgarden – currently a java program called HexToImage.jar, (located in the help menu from sketchgarden.co).
Open a terminal window, and navigate to the directory with your .hex file and the hextoimage.jar app.
Type in java -jar HexToImage.jar yourfilehere.cpp.hex yourfilehere.bin

For me, it was:

cd desktop
cd environmental
java -jar HexToImage.jar PachubeV3_LibTemp_Motion_light_Webserver_SEEDLCD_JH.cpp.hex PachubeV3_SeedLCD_for_Sketchgarden.bin

 

I’m going to bash your head in.

#6 Upload To Sketchgarden

Take your compiled and converted .bin file and upload it as a new sketch. Dont forget to copy in your source code to remind you of what this file does.

 

It’s Peanut Butter sketchy time

#7 Upload to your nanode

click and  drag the file from the left over to the grey square… it took me a few tries, the page seems buggy. then click Upload Sketch.

Master preview artist, at your service.

I dont do GIFS.

# 8 Wait a few minutes, then give up thinking it failed….hours later return and rejoice that it actually did work, but you were to impatient the first time around!

patience

Win.

 

Somewhere along the line I had an issue with my nanode resetting every time I try to capture from more than 3 sensors. Currently, I am only capturing Temperature and Light information. The motion capture device (A PIR motion sensor) was randomly freezing my Nanode and causing it to stop reporting data. Unfortunately I uploaded my old code in this ketch, but I should be able to recall what I did to get it to work. I beleive i excluded the reading of those sensor pins, and filled the values with an arbitrary or duplicate value.

 

It doesn’t look like much, but I made it.

 

final enclosure

final enclosure. 

 

Leave a Comment

Nanode: Round 2 – Pachube with Various sensors

January 5, 2012

Webservers are so 1990’s. We need fresh ways of collecting and displaying data. Too bad there isn’t a “cloud” service out there for that.

Oh, wait, There is!

Following the basic code on the Nanode website I was able to set up my own Pachube (Now COSM Xively) account and configure my nanode to stream data over to their logging service.

Here is the list of items used in this build:

Nanode V5 by WickedDevice
ModernDevice TempSensor (i2c temperature sensor) from Liquidware, which is a breakout for the TMP421  from Texas Instruments.
Serial LCD v1.1 – 16×2 “Twig” Grove display from SeeedStudios SeeedStudio “Grove” light sensor v 1.0
PIR sensor (Motion Detector) , Ebay

Programming:

Sample Code

The internal IP address is staticly defined, along with the DNS settings for pachube.com. This was cobbled together in november / december, and since then new code is available for proper DNS resoloution.

Upon power up, the Nanode checks it is connected to the network, then polls the sensors and stores them to variables. It refreshes the LCD and “prints” it to the screen, prints to the serial port, and shoots the data up to pachube.com

 

As seen in my office, hanging precariously off my booklamp.

 

 

 

Leave a Comment

CODE:SEEDLCD_JH

December 20, 2011

Download [zip] PachubeV3_LibTemp_Motion_light_Webserver_SEEDLCD_JH

————————

 

/*
* Arduino + Analog Sensors Posted to Pachube
*      Original Source Created on: Aug 31, 2011
*          Author: Victor Aprea
*   Documentation: http://wickeddevice.com
*
*       Source Revision: 587
*
* Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0
*    Utilized in the following example by JarenHavell.com in “Nanode Round 2”
*
* HAREDWARE SETUP
* Modern Device TempSensor i2c Temperature sensor – analog pins 2,3,4,5 – from liquidware http://www.liquidware.com/shop/show/SEN-TMP/Temp+Sensor
* Generic Motion Sensor Analog pin 0 – from Ebay
* Grove – Serial LCD – “twig serial LCD” 2×16 chars-  from Seeedstudios  http://www.seeedstudio.com/wiki/index.php?title=Twig_-_Serial_LCD
*
*
*
*
*/

#include “EtherShield.h”
//for temperature Sensor
#include “Wire.h”
#include “LibTemperature.h”
#include <SerialLCD.h>
#include <NewSoftSerial.h> //this is a must
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* The following #defines govern the behavior of the sketch. You can console outputs using the Serial Monitor
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#define MY_MAC_ADDRESS {0x54,0x55,0x58,0x10,0x00,0x25}               // must be uniquely defined for all Nanodes, e.g. just change the last number
//#define USE_DHCP                                                     // comment out this line to use static network parameters
#define PACHUBE_API_KEY “INSERT YOUR OWN PACHUBE KEY BETWEEN THE QUOTES” // change this to your API key
#define HTTPFEEDPATH “/v2/feeds/#####”                               // change this to the relative URL of your feed, #’s replaced with your own feed.
#define SENSOR2_ANALOG_PIN 1
#define SENSOR3_ANALOG_PIN 0
//************************************************
//-the temperature stuff – variables
LibTemperature temp = LibTemperature(0); // more temperature variable stuff
//*************************************************

SerialLCD slcd(5,6); //assign soft serial pins 5 as RX, 6 as TX.
//Connect 6 to the RX of LCD, and 5 to TX of LCD.

//sets size of LCD
const int numRows = 2;
const int numCols = 16;

#define DELAY_BETWEEN_PACHUBE_POSTS_MS 15000L
#define SERIAL_BAUD_RATE 19200

#ifndef USE_DHCP // then you need to supply static network parameters, only if you are not using DHCP
#define MY_IP_ADDRESS { 192,168,  1,175}
#define MY_NET_MASK   {255,255, 255,  0}
#define MY_GATEWAY    { 192,168,  1,  1}
#define MY_DNS_SERVER {  8,  8,  8,  8}
#endif

// change the template to be consistent with your datastreams: see http://api.pachube.com/v2/
#define FEED_POST_MAX_LENGTH 256
static char feedTemplate[] = “{\”version\”:\”1.0.0\”,\”datastreams\”:[{\”id\”:\”sensor1\”, \”current_value\”:\”%d\”},{\”id\”:\”sensor2\”,\”current_value\”:\”%d\”},{\”id\”:\”sensor3\”,\”current_value\”:\”%d\”}]}”;
static char feedPost[FEED_POST_MAX_LENGTH] = {0}; // this will hold your filled out template
uint8_t fillOutTemplateWithSensorValues(uint16_t node_id, uint16_t sensorValue1, uint16_t sensorValue2, uint16_t sensorValue3){
// change this function to be consistent with your feed template, it will be passed the node id and four sensor values by the sketch
// if you return (1) this the sketch will post the contents of feedPost to Pachube, if you return (0) it will not post to Pachube
// you may use as much of the passed information as you need to fill out the template

snprintf(feedPost, FEED_POST_MAX_LENGTH, feedTemplate, sensorValue1, sensorValue2,sensorValue3); // this simply populates the current_value filed with sensorValue1
return (1);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* You shouldn’t need to make changes below here for configuring the sketch
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

// mac and ip (if not using DHCP) have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = MY_MAC_ADDRESS;

// IP address of the host being queried to contact (IP of the first portion of the URL):
static uint8_t websrvip[4] = {173,203, 98, 29 }; // should be resolved through DNS

#ifndef USE_DHCP
// use the provided static parameters
static uint8_t myip[4]      = MY_IP_ADDRESS;
static uint8_t mynetmask[4] = MY_NET_MASK;
static uint8_t gwip[4]      = MY_GATEWAY;
static uint8_t dnsip[4]     = MY_DNS_SERVER;
#else
// these will all be resolved through DHCP
static uint8_t dhcpsvrip[4] = { 0,0,0,0 };
static uint8_t myip[4]      = { 0,0,0,0 };
static uint8_t mynetmask[4] = { 0,0,0,0 };
static uint8_t gwip[4]      = { 0,0,0,0 };
static uint8_t dnsip[4]     = { 0,0,0,0 };
#endif

long lastPostTimestamp;
boolean firstTimeFlag = true;
// global string buffer for hostname message:
#define FEEDHOSTNAME “api.pachube.com\r\nX-PachubeApiKey: ” PACHUBE_API_KEY
#define FEEDWEBSERVER_VHOST “api.pachube.com”

static char hoststr[150] = FEEDWEBSERVER_VHOST;

#define BUFFER_SIZE 550
static uint8_t buf[BUFFER_SIZE+1];

EtherShield es=EtherShield();

void setup(){
Serial.begin(SERIAL_BAUD_RATE);
Serial.println(“Nanode + LibTemp Sensor + Pachube = Awesome”);
// Initialise SPI interface
es.ES_enc28j60SpiInit();

// initialize ENC28J60
es.ES_enc28j60Init(mymac, 8);

#ifdef USE_DHCP
acquireIPAddress();
#endif

printNetworkParameters();

//init the ethernet/ip layer:
es.ES_init_ip_arp_udp_tcp(mymac,myip, 80);

// init the web client:
es.ES_client_set_gwip(gwip);  // e.g internal IP of dsl router
es.ES_dnslkup_set_dnsip(dnsip); // generally same IP as router

Serial.println(“Awaiting Client Gateway”);
while(es.ES_client_waiting_gw()){
int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
es.ES_packetloop_icmp_tcp(buf,plen);
}
Serial.println(“Client Gateway Complete, Resolving Host”);

resolveHost(hoststr, websrvip);
Serial.print(“Resolved host: “);
Serial.print(hoststr);
Serial.print(” to IP: “);
printIP(websrvip);
Serial.println();

 

es.ES_client_set_wwwip(websrvip);

lastPostTimestamp = millis();
}

void loop(){
long currentTime = millis();

int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
es.ES_packetloop_icmp_tcp(buf,plen);

if(currentTime – lastPostTimestamp > DELAY_BETWEEN_PACHUBE_POSTS_MS || firstTimeFlag){
firstTimeFlag = false;
uint16_t sensorValue1 = ((temp.GetTemperature() * 9 / 5) + 32);;
uint16_t sensorValue2 = analogRead(SENSOR2_ANALOG_PIN);
uint16_t sensorValue3 = analogRead(SENSOR3_ANALOG_PIN);

if(fillOutTemplateWithSensorValues(0, sensorValue1, sensorValue2, sensorValue3)){
Serial.print(“Posting sensor values to Pachube: “);
Serial.print(sensorValue1, DEC);
Serial.print(“, “);
Serial.print(sensorValue2, DEC);
Serial.print(“, “);
Serial.print(sensorValue3, DEC);
Serial.print(“, “);
Serial.println();

//begin coimmunication, turn on display, turn on backlight
slcd.begin();
slcd.clear();
slcd.backlight();

//Col, row
slcd.setCursor(0,0);  // Scroll to X,Y position
slcd.print(“Temp”);
slcd.setCursor(0,1);  // Scroll to X,Y position
slcd.print(sensorValue1, DEC);
slcd.print(“F”);

slcd.setCursor(5,0);  // Scroll to X,Y position
slcd.print(“Motion”);
slcd.setCursor(5,1);  // Scroll to X,Y position
slcd.print(sensorValue2, DEC);

slcd.setCursor(12,0);  // Scroll to X,Y position
slcd.print(“Lht”);
slcd.setCursor(12,1);  // Scroll to X,Y position
slcd.print(sensorValue3, DEC);

es.ES_client_http_post(PSTR(HTTPFEEDPATH),PSTR(FEEDWEBSERVER_VHOST),PSTR(FEEDHOSTNAME), PSTR(“PUT “), feedPost, &sensor_feed_post_callback);
}
lastPostTimestamp = currentTime;

 

}

}

#ifdef USE_DHCP
void acquireIPAddress(){
uint16_t dat_p;
long lastDhcpRequest = millis();
uint8_t dhcpState = 0;
Serial.println(“Sending initial DHCP Discover”);
es.ES_dhcp_start( buf, mymac, myip, mynetmask,gwip, dnsip, dhcpsvrip );

while(1) {
// handle ping and wait for a tcp packet
int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

dat_p=es.ES_packetloop_icmp_tcp(buf,plen);
//    dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
if(dat_p==0) {
int retstat = es.ES_check_for_dhcp_answer( buf, plen);
dhcpState = es.ES_dhcp_state();
// we are idle here
if( dhcpState != DHCP_STATE_OK ) {
if (millis() > (lastDhcpRequest + 10000L) ){
lastDhcpRequest = millis();
// send dhcp
Serial.println(“Sending DHCP Discover”);
es.ES_dhcp_start( buf, mymac, myip, mynetmask,gwip, dnsip, dhcpsvrip );
}
}
else {
return;
}
}
}
}
#endif

// hostName is an input parameter, ipAddress is an outputParame
void resolveHost(char *hostName, uint8_t *ipAddress){
es.ES_dnslkup_request(buf, (uint8_t*)hostName );
while(1){
int plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
es.ES_packetloop_icmp_tcp(buf,plen);
if(es.ES_udp_client_check_for_dns_answer(buf, plen)) {
uint8_t *websrvipptr = es.ES_dnslkup_getip();
for(int on=0; on <4; on++ ) {
ipAddress[on] = *websrvipptr++;
}
return;
}
}
}

void sensor_feed_post_callback(uint8_t statuscode,uint16_t datapos){
Serial.println();
Serial.print(“Status Code: “);
Serial.println(statuscode, HEX);
Serial.print(“Datapos: “);
Serial.println(datapos, DEC);
Serial.println(“PAYLOAD”);
for(int i = 0; i < 100; i++){
Serial.print(byte(buf[i]));
}

Serial.println();
Serial.println();
}

// Output a ip address from buffer from startByte
void printIP( uint8_t *buf ) {
for( int i = 0; i < 4; i++ ) {
Serial.print( buf[i], DEC );
if( i<3 )
Serial.print( “.” );
}
}

void printNetworkParameters(){
Serial.print( “My IP: ” );
printIP( myip );
Serial.println();

Serial.print( “Netmask: ” );
printIP( mynetmask );
Serial.println();

Serial.print( “DNS IP: ” );
printIP( dnsip );
Serial.println();

Serial.print( “GW IP: ” );
printIP( gwip );
Serial.println();
}

 

 

1 Comment

Nanode: Round 1 – Webserver and temperature sensor

September 26, 2011

First project with the nanode was getting a sensor to display the current temperature, then display it on a self refreshing webpage. Pretty simple, since I have already done this before. Just a few minor differences in how the libraries work. Currently it is pulling the temperature data from a ModernDevice temp sensor, and displaying on this website, which refreshes every second. See it in action here.

My Code:

Nanode_Server [.ZIP FILE!]
Contains: (my simple Arduino Sketch, Libraries for the Nanode compatable ethernet shield and the Lib Temp Sensor )

Code examples:
https://github.com/Nanode/Webserver-Live-Thermistor-Reading/blob/master/Webserver_Live_Thermistor_Reading.pde
http://www.liquidware.com/apps/show/77

Programming help:
http://arduino.cc/en/Reference/Array
http://dereenigne.org/electronics/arduino/arduino-float-to-string

hardware:
http://shop.moderndevice.com/products/tmp421-temperature-sensor   (As seen in my prior post)
http://www.jarenhavell.com/blog/nanodefirstimpressions/

Leave a Comment

Nanode : First Impressions

September 25, 2011

The Nanode kit – an open designed, web enabled, “arduino compatible”? for $39 Are you kidding me? Thats a great deal!

The Nanode!

That was the first thought that crossed my mind when I saw the Nanode at the World Maker Faire in New York. This product is now available (and manufactured) in the USA thanks to the colaboration of its original designer, Ken Boak from London Hackspace and Vic and Dirk from WickedDevice. My board revision (Nanode 5) was the first set of kits available in the US.

I had heard of the nanode before, but never really was able to get over the international shipping costs and was not sold on a Microchip ethernet controller when the “standard” is any shield based on the Wiznet ethernet controller.

but $35? Heck. Why not!

So I bought one.

 


And it works!


Here is my take on the assembly.

 

HOLY RESISTORS

The online pictorial building guide included plenty of visual and text instructions, however there were a few discrepancies between my board and the pictures. This is not surprising, as the PCB pictured in the instructions is from London Hackspace, where as my device is a new product made in the USA and sold by WickedDevice. They are working on their own documentation, as it should be available soon.

Most of the differences were minor  component variations (the level shifter and capacitors were from a different manufacturer, the PCB was a different revision with a different screen print.

 

 

 

 

The first item to catch my eye was the SMT SOT23 labeled 11AA02E48 which is a 3 pin serial eeprom, pre-soldered to the bottom of the board. This was identified as the “MAC Address IC” in the instructions. This kit is intended to be assembled by the hobbyist, and most of us dont have surface mount soldering equipment (Well, some of us do). Props to the guy who has to hand solder and pack all these boards!

 

Another set of empty pads left room for an 8-lead SOIC, labeled 23k256, which is a 256k of SRAM connected to the SPI bus. No chip included with the N5 kit, but its listed as an optional component (original design notes here) to be used for additional code storage or data logging  Ethernet based arduino sketch uploads! This is based on a new bootloader called WickedBoot. Code is available in the invite-only Sketchgarden beta site. Code was previously in in development by the Arduino guys, but the guys over at wickedDevice are not quite ready to let their code go mainstream yet.  (Other similar projects for TFTP arduino boot available here )

 

 

 

 

 GOTCHA’S

 


C'mon, Baby, Let's Do The Twist.

The only real “gotcha” is the 3.3v voltage regulator. The orientation does not match the orientation of the screen print. There is a “note” and a dashed line,probably a quick fix enabling them to deliver a working product in time for MakerFaire. This orientation is addressed in the documentation, but could be easily missed if you are used to jumping in without reading directions first (guillty as charged!). This has been identified by WickedDevice as something that is going to be fixed in version 6.

 

 

 

 

 

 

 

 

Once everything is assembled, loading up the first test sketch only requires a minor tweak to the line to tell it to use Pin 8. The code was developed for the Nuelectronics EtherShield The source code is up on Github, but hopefully there will be a custom library for the Nanode available directly from WickedDevice shortly.

Modify this line to specify pin 8.

 

Pop the ethernet cord in, fire up the browser, and go to the default IP address. you should see the first webpage served by the new Nanode!

Woot!

 

AWESOMESAUCE

I did notice  lots of spare holes for missing components- 2 zener diodes, 2 resistors and a capacitor was left out- the instructions make reference to a Virtual USB option. Sweet!  A quick search on their Wiki page reveals that its in the works,  Code for virtual USB available here.

USB and FTDI header

 

The thing that really got me excited was the Ethernet Bootloader. WickedDevice have a video showing this over on their blog. Cant wait till they release the code!

Soft lighting sets the mood for some sweet ethernet and I²C lovin'

 

 

Overall I think it’s a great buy for under $40. Go buy one one!

Available from the following vendors:

WickedDevice -USA/Canada/Mexico

Earthshine Electronics -UK

SK Pang Electronics -UK

1 Comment

CODE: temperature and motion – server

July 10, 2011

Look at this code, bishes – for the wiznet based ethernet shield.

/*
LiquidCrystal Library - display() and noDisplay()
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
The circuit:
* LCD RX pin to digital pin d2
* temp sensor analog pins a2,a3,a4,a5
* Light Sensor analog pin a0 (TEMT6000)
* xbee tx d0
* xbee rx d1
* Ethernet shield attached to pins 10, 11, 12, 13
* led Pin D3
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
// include the library code:
#include
#include
#include
#include
#include
//------------------Start web server Setup -mac and IP address---------
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,0,0,174 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
//----------------- End Web Server Setup--------
//------------------Start i2c LCD backpack setup----------
// since the LCD does not send data back to the Arduino, we should only define the txPin
#define txPin 2 //pin used for i2c based LCD backpack
SoftwareSerial LCD = SoftwareSerial(2, txPin);
const int LCDdelay=10; // conservative, 2 actually works
//------------------End i2c LCD backpack setup
//-----------------Setup the Variables for sensors-------
int sensorPin1 = A0; // select the input pin for the light sensor
int sensorPin2 = A1; // select the input pin for the PIR sensor
int sensorValue1 = 0; // variable to store the value coming from the Light-sensor, default 0
int sensorValue2 = 0; // variable to store the value coming from the PIR-sensor, default 0
float tempF = 0; // variable to store the value coming from the temp sensor after converted to F degrees
const int ledpin3 = 3; //pin corresponding to pin 3 for LED
//-----------------End sensor variable madness------------
//-----------------Start LCD controlls-------------------
// wbp: goto with row & column
void goTo(int row, int col) {
LCD.print(0xFE, BYTE); //command flag
LCD.print((col + row*64 + 128), BYTE); //position
delay(LCDdelay);
}
void clearLCD(){
LCD.print(0xFE, BYTE); //command flag
LCD.print(0x01, BYTE); //clear command.
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(157, BYTE); //light level.
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(128, BYTE); //light level for off.
delay(LCDdelay);
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.print(0xFE, BYTE);
}
//---------------------End LCD controlls-----------------
//---------------------Begin LCD setup -----------------
void setup() {
pinMode(txPin, OUTPUT); //sets up Pint as output to LCD
LCD.begin(9600);
clearLCD();
goTo(0,0);
//}
//--------------------End LCD Setup-----------------------
//---------------------Begin LED Output-------------------
pinMode(3, OUTPUT); //setup pin for digital out - pin 3
//---------------------End led Output---------------------
//------------------Begin Web SErver Setup---------------
//void setup()
//{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
//------------------End Web SErver Setup----------------
//-------------------Begin Sensor read and LCD control----------------------
void loop() {
// read the value from the sensors:
sensorValue1 = analogRead(sensorPin1); //light sensor
sensorValue2 = analogRead(sensorPin2); //PIR
LibTemperature temp = LibTemperature(0); // reads temperature in Celcius
// convert to degF
tempF = (temp.GetTemperature() * 9 / 5) + 32;
//stores float to int because serlcd wont send floats
int tempfd = tempF;
// Print sensor value to the LCD.
goTo(1,0);
LCD.print("Light");
goTo(0,0);
LCD.print(" ");
goTo(0,0);
LCD.print(sensorValue1);
goTo(1,6);
LCD.print("PIR");
goTo(0,6);
LCD.print(" ");
goTo(0,6);
LCD.print(sensorValue2);
goTo(1,10);
LCD.print("Temp F");
goTo(0,12);
LCD.print(tempfd);
//Iluminate LED if motion.
digitalWrite(3, HIGH); // set the LED on
{if (sensorValue2 < 10) {
// no motion
digitalWrite(ledpin3, LOW); // set the LED off
}
else {
// motion
digitalWrite(ledpin3, HIGH); // set the LED ON
}
}
delay(500);
//}
//-----------------End Sensor read and LCD control------------------------
//-----------------Web Server code---------------------------
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
//for (int analogChannel = 0; analogChannel < 1; analogChannel++) {
int analogChannel = 0; //select channell 1
client.print("Light Level from channel ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
client.print("Temperature is ");
client.print(tempfd);
client.print(" Degrees F");
client.println("
");
//}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
//--------------------End web server code ----------------------
Leave a Comment

Maker Faire 2011, San Francisco

May 23, 2011

I’m at the Maker Faire in San Francisco this weekend. I got a chance to meet lots of cool people – Jeri Ellsworth, Jeff Keyzer, Garret Mace, Ian Lesnet and lots of other really awesome individuals.

I stopped in the Element 14 booth and had a chat with one of their Software developers, Drew Fustini, who is also a member of Pumping station one in chicago. We talked about The Amp Hour and who we had seen here in the expo hall. He hooked me up with a free Element 14/ Adafruit mini POV (persistence of Vision) solder kit and a station to put it together. As I was sitting working away, who should arrive but the Mighytohm (Jeff) himself!

Later in the day (once my mini POV was complete) I got a chance to talk to Ian from Dangerous prototypes. He had a new oscilloscope board that they had on display. He showed me some of its features, though we failed to read anything lower than 50 mhz square waves. He also showed me the BusPirate, and how it can be used to interact and read back data from various devices.

I then moved on to the MaceTech where I chilled in the awesome party tent with Garret and purchased a Centipede shield and an Octobright Cyanea .

I also ran into Mark Sproul from Rutgers University and Fubar Labs (Hes the guy who did all the pic software development for the chipKIT Max32, and Rick Anderson did the compiler modifications. (EDIT: Hack-a-day had some additional coverage on Mark from Saturday’s event here. )

Basically he said the Ethernet shield has some IC’s that talk on the physical level, and is going to be out in July.
He also was referencing how the kit is possible, by working at the abstraction layer and making a simple text file that goes between the lower code and the h file. “Give me a GCC compiler, any GCC compiler, and ill have it running in a week”

He said he wants to work on ARM Cortex, and some other platforms, and that essentially its so simple you could do it, its just a text file.
By the way, He’s just as much a hacker as anyone. While yes, Digilent sent him lots of free dev boards, hes not getting paid to develop this.

Off to day two of Maker Faire 20011, San Francisco Bay, and the “Bring a Hack” Meetup!

Leave a Comment

Server Room Environmental Monitoring -Light and Temperature

April 27, 2011

Did I leave the light on in the server room again? Kind of like “did I leave the oven on”… its going to bug me all night!
At least I am well on my way to answering that, and several other questions I might be wondering.

My goal with this project is to set up a remote monitoring device I can place in my server room that will display basic information such as temperature, ambient light values, decibels, current draw, etc.

Right now I have a 16×2 character LCD from JKdevices. Its compatible with the Hitachi HD44780, so it works great with the Arduino LiquidCrystal library. I have it connected in 4bit mode.

Arduino with potentiometer, temperature and light sensors

 

I have the arduino reading the 3 sensors and storing them to variables. the light and potentiometer values are stored to an integer, and the temperature is stored in a float. Those variables are then “printed” to the LCD screen, every 500 milliseconds.

Here is the temperature sensor  (based around Ti’s TMP421), which I purchased from Liquidware. the breakout board is manufactured  by Modern Devices.  It’s accurate to within +/- 1 degree Celsius, or for us Americans, +/- 1.8 degrees Fahrenheit. It’s based off the I2C protocol, and includes a library to  make things (somewhat) easier to use.

Modern Devices I2C Temp Sensor

 

The light sensor is the same sensor I used in my 555 contest submission. It is manufactured by Vishay. The TEMT6000 [datasheet] from Sparkfun Electronics . Right now I have no idea what units i am reading, just that the value changes proportionally to the amount of light.

The final item on the display is displaying the value from a potentiometer. Not much use for that unless I need a position sensor for something that rotates or opens.

I’m ordering a few more sensors – more to come as parts come in!

—————-

LCD Pinout

Blue Backlit LCD
Standard HD44780 Interface
Runs on 5 volts
16×2 Character Display
4 Mounting Holes
pin    symbol    description
1    GND    Ground
2    Vcc    Vcc (+5V) also powers backlight
3    V0    Contrast adjustment
4    RS    Register select: low = instruction, high = data
5    R/W    low = write, high = read
6    E    Enable (active high)
7    DB0    Data-bus bit 0 (not used in 4-bit mode)
8    DB1    Data-bus bit 1 (not used in 4-bit mode)
9    DB2    Data-bus bit 2 (not used in 4-bit mode)
10    DB3    Data-bus bit 3 (not used in 4-bit mode)
11    DB4    Data-bus bit 4
12    DB5    Data-bus bit 5
13    DB6    Data-bus bit 6
14    DB7    Data-bus bit 7
15    LED+    Positive backlight supply (if used)
16    LED-    Negative backlight supply (if used)

————–

Update 5/13/2011

PIR sensor and Audio level sensor have arrived, along with ethernet shield. Trying to get something solid together over the weekend, before next week’s Maker Faire in SF.

————-

Update 6/14/2011

Received new parts – sparkfun i2C  backpack for LCD.
Ran into a snag with my Arduino duemilanove -i think i blew up burned out the FTDI chip! Not to worry, I hooked up the Xbee for easy “wireless” programming! Got the backpack soldered to the LCD and got it displaying temperatures. Biggest issue was finding the right code to talk to an i2c display, then pushing over the temperature data. The temperature from the sensor is stored as a Float. Floats will not transfer over the serLCD from Sparkfun, so I needed to change it to an integer first. Who knew?

 

 

6 Comments

Charliplexed Led E-textile Patch

April 15, 2011

Did you bring a hack? – (Spring of 2011 -Pre Maker Faire SF Bay Area)

Answering this question was the driving motivation in getting this project underway. After seeing several Charlieplex links on hack-a-day, I decided it was high time that I give it a try myself. I wanted something I didn’t have to carry around, so a T-shirt seemed like a logical choice. I had seen some other LED based e-textiles, but didn’t want to use huge 3mm or 5mm LED’s. Surface Mount Led’s came to mind, but I was not sure how to go about soldering anything to conductive thread.

Fortunately, I ran across an article describing how to mount surface mount LEDs to fabric by way of soldering small crimp beads to each end. This provided a place to loop the conductive thread through the LED.

First, acquire crimp beads and leds:

Seccond: Assemble

Each SMT led has a silver ring attached to it.

Next I had to decide how to design and control the Charlieplex.

The first step, was a prototype circuit and layout. I really have to thank this guy [Ben] for posting helpfull information on the web. His 5×4 Charliplex display walkthrough provided me with the design I used to lay out the e-textile. I ended up taking his hand drawn schematic and using it as my t-shirt layout with minimal changes. I don’t have a printer at home, so I actually traced this schematic from a sheet of paper I placed over my monitor, and transferred that to the front and back of the fabric.

Then I added the conductive thread and components.

 

then I cut out a square, attached some connectors and an Arduino, and stuck it to a shirt!

20120520-081355.jpg

Leave a Comment

« Previous PageNext Page »