Server Room Environmental Monitoring – Part 2

September 4, 2013 by · Leave a Comment
Filed under: Arduino, Blog, Projects 

[This post should have been published 2 years ago… oops]

In an earlier post I began working on a Server Room Environmental Monitoring based on an Arduino.

Arduino with Temperature and Light sensors

Arduino with Temperature & Light sensors and potentiometer.

 

This project was started just for fun-  I wanted to learn more about micro controllers (specifically the arduino platform), and partially because I didn’t have room in my technology budget at work to do it the “right way” (not even sure what way that is for a small business…netbotz?). I wanted to improve on my original idea by having it accessible remotely via my network. Thus we end up with our first semi-finished prototype:


prototyping on breadboards

prototyping on breadboards

This device monitors the temperature and ambient light readings and displays the values on an LCD and displays them in a browser windows rendered in html. I have the 2nd iteration pretty much completed, just working through some of the programming issues. [At the time] I wanted to expand the sensors to include multiple i2c temperature sensors, and possibly make the LCD display wireless via Xbee. Later posts will show I ended up using a Nanode with Grove sensors [but I digress as this is documenting the original build.]

Semi- finalized product

Semi- finalized product

Components:

Arduino Duemilanove (ATMEL 328p)
DFRobot Ethernet Shield DFR0110, Powered by a Wiznet W5100
Sparkfun Protoboard (v2)
TEMT6000  Ambient Light Sensor by Vishay via the Sparkfun Breakout Board
JK Device HD44780 Compatable 2 x 16 Char LCD display
Sparkfun SerLCD I2C backpack
Adafruit Arduino enclosure

 

I had to add the Xbee out of necessity (I had them from another project, but when I burned out the FTDI chip on the Arduino I had no way of programming it, but it turned out being rather convenient!)
Two Xbee with a chip based 1mw antenna.
Xbee Explorer Regulated
Xbee Explorer USB

Generic PIR Sensor module from ebay – looks very similar to this.

I have most of the code working. I made the code available as a download. It includes the two libraries for the I2C Serial LCD backpack controls and the LibTemperature library for the I2c temperature module:
Arduino_Environmental_Monitoring_Webserver [this is a .zip file]
The code is also available here in plaintext [here]

 

 

This is how it works:

pull in the libraries for all the different modules
set up the variables to store numbers
some code to control the LCD
Set the pins for the LCD and for the LED
Setup the MAC and IP for the Ethernet Shield
read the sensors and store the values to the variables
convert the C temperature to F and store to a different variable.
Print the values to the display
Send the values inside HTML to the browser
Send the browser a command to refresh every X seconds.

 

The Challenges:

When using my Arduino for another project  I was testing a large number of SMT led’s all at once, pulling a decent amount of current through the 3.3v regulator, far exceeding the 50Ma spec of the L.D.O inside the FTDI. I inadvertently short circuited or over drive the 3.3v line , burning out the FTDI USB to RS232 chip on the board. I ended up utilizing two Xbee modules and connecting one to the TX /RX lines for serial connection. This worked out great, because It forced me to get the Xbee working! I now have 2 Xbee units paired for serial communications.

There were some small issues with the Ethernet Shield. #1. The pin map on this particular model uses (Arduino) pins A4 and A5 to access the SD card, which I am currently using for my I2C temperature sensor communication. There were also issues with the bottom of my proto-shield hitting the ethernet plug and grounding out, so I extended the pins the quick and dirty way by  extending it with pin headers.

The enclosure from Adafruit fit great, but the end plate did not work with the Ethernet shield. I had to discard the plate for the connectors.

 

mounted, splayed

mounted, splayed

Dirty Coding Schemes:

I was getting some odd looking numbers on the LCD screen when testing it in a variety of light and temperature ranges. The number would “print” to the screen, and when it poured over to the 3rd digit, that digit would stay on the screen, regardless of what was being written to the block immediately to the left.

[LCD]

I didn’t bother figuring out how to erase data or clear the screen between refreshes, so in my code I had it over-write 4 blank spaces, then go back to the beginning and write the data value. probably a very dirty way of clearing that part of the screen.

[Browser Refresh]

the arduino code strings together the HTML and streams it to your browser. there is a small snippet of meta html HTTP-EQUIV “REFRESH” that tells your browser to refresh every few seconds to see the new values gathered in the loop code.

[Hard Coded IP Address]

Unfortunately, I found that the DHCP library did not work so well for me. I decided to hard-code my device. this has certain advantages, but makes it less portable. Not everyone uses a class B /16 subnet at home.

 

Final Results:

 

Finalized

Finished device

 

 

guts

internals

 

connectors... the business end

connectors… the business end

 

 

Nanode Round 3: SketchGarden

March 17, 2012 by · Leave a Comment
Filed under: Arduino, Projects 

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. 

 

CODE:SEEDLCD_JH

December 20, 2011 by · 1 Comment
Filed under: Arduino 

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();
}

 

 

Nanode: Round 1 – Webserver and temperature sensor

September 26, 2011 by · Leave a Comment
Filed under: Arduino, Blog, Projects 

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/

CODE: temperature and motion – server

July 10, 2011 by · Leave a Comment
Filed under: Arduino, Blog 

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

Server Room Environmental Monitoring -Light and Temperature

April 27, 2011 by · 6 Comments
Filed under: Arduino, Projects 

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?

 

 

Charliplexed Led E-textile Patch

April 15, 2011 by · Leave a Comment
Filed under: Electronics, Projects 

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

Laser Beams and 555’s

March 2, 2011 by · Leave a Comment
Filed under: Electronics, Projects 

This page serves as my contest entry for the 555 timer design contest.

I have created a laser trip wire that actuates a camera. An ambient light sensor by Vishay ,  the TEMT6000 [datasheet] from Sparkfun Electronics, acts as  an NPN transistor attached to a 555 in BiStable mode. The output is sent to a logic inverter for quick visual status, then off to another 555 in Monostable configuration. The output from that 555 can be used to actuate any number of devices (Electric squirt gun, Sirens, Nerf guns, etc.), but in this example I have my camera set up in continious fire mode, as the output stayes on for several seconds. This could be used for catching a burgler (who probably wants to steal my camera), or more usefull items such as taking pictures at the end of a race.

I have a green laser for visuals, but it is probably possible to use alternate frequencys or light that are less visible to the human eye.

Description:

laser ——-Light sensor(npn) ~555 bistable> inverter logic chips and Status leds> 555 monostable >transistor (npn)-relay >camera trigger > CLICK!

The block diagram:

The schematic:

Video of my submission below:

http://www.youtube.com/watch?v=VfJCeC1byJE

Please Be Discrete

January 20, 2011 by · 1 Comment
Filed under: Projects 

The 555contest has triggered (pun!)  a desire to be discrete. No, im not talking about conservative speech or keeping secrets, im talking individual componants!

It looks like im not alone! Someone has already been looking into this on Dave Jones’s eevblog

The forum user has linked to a schematic which may have been used to digitaly simulate the inner workings of the 555 timer.

I recall using a tool called (Circuit builder?) in high school to design basic digital/analog circuits. I wonder if i still have it installed on an old laptop somewhere…

My goals:
Reverse engineer the inner workings of a 555 timer chip.
Build a functioning 555 timer chip with “socket” extension that can be plugged into various “test boards”.
Make 2-3 test boards (blinky lights, pwm controller, one shot/debounce)
Design and etch clean looking boards for the 555 and test boards

Tools:
Simulation software (circuit builder, pspice or lt spice)
Circuit board design software (eagle)

Resources:
http://www.designinganalogchips.com/
http://www.waitingforfriday.com/index.php/4-Bit_Computer
Linear Technology LTspice IV …examples\Educational\NE555.asc
http://translate.google.com/translate?hl=en&sl=es&tl=en&u=http%3A%2F%2Fsites.google.com%2Fsite%2Fprecisionaudiotv%2FHome

Parts list (potential):
Transistors: BC847B (NPN ones) and BC857B (PNP ones)
Q1 N5 5 N7 1 NP
Q2 N1 6 N6 1 NP
Q3 N1 N6 N8 1 NP
Q4 N5 N7 N8 1 NP
Q5 7 N16 1 1 NP
Q6 N17 N14 1 1 NP
Q7 N1 N1 N3 1 PN
Q8 N17 N1 N2 1 PN
Q9 1 N5 N2 1 PN
Q10 N5 N5 N4 1 PN
Q11 N11 N20 N9 1 PN
R1 8 N3 4.7K
R2 8 N2 830
R3 8 N4 4.7K
R4 8 N9 1K
R5 8 5 5K
R6 8 N22 6.8K
Q13 1 2 N10 1 PN
Q14 N14 N10 N11 1 PN
Q15 N13 N12 N11 1 PN
Q16 N13 N15 N12 1 PN
R7 N14 1 100K
R8 N13 1 100K
R9 N15 5 5K
R10 N15 1 5K
R11 N8 1 10K
Q17 N16 4 N18 1 PN
Q18 N19 N17 1 1 NP
R12 N18 N20 5K
Q19 N20 N20 8 1 PN
Q20 N21 N20 8 1 PN
Q21 N21 N19 1 1 NP
R13 N17 N21 4.7K
Q22 8 N22 N23 1 NP
Q23 N22 N21 N24 1 NP
Q24 8 N23 3 1 NP
R14 3 N23 3.9K
Q25 3 N25 1 1 NP
R15 N25 N24 220
R16 1 N24 4.7K
R17 N24 N16 10K
D2 3 N22 D
D1 N18 N19 D
.MODEL NP NPN(BF=125 Cje=.5p Cjc=.5p Rb=500)
.MODEL PN LPNP(BF=25 Cje=.3p Cjc=1.5p Rb=250)
.MODEL D D(Is=1e-12 Cjo=1p Rs=5

to be updated as the project procedes!

Arduino – Displays

January 18, 2011 by · Comments Off on Arduino – Displays
Filed under: Arduino, Projects 

Picked up my first display for my Arduino Duemilanove.

I saw an article over on HackaDay and it reminded me of a previous submission related to a custom job done up overseas in a VW TDI  to monitor various bits, mounted inside a dash button!

Owning a VW TDI, and wanting to monitor EGT, boost, temps, etc motivated me to at least investigate how difficult it is to interface the Arduino with a full color RGB LCD.

After a quick Google search  for “RGB LCD Shield for Arduino”,  I ran across the following product from NKC Electronics.

65k RGB LCD Shield from NKC Electronics - KIT

After a little playing I got the board soldered up and displaying the demo images and some custom text. The arduino demo code library was written by Henning Karlsen for NKC, and is released under the GNU Lesser General Public License. Really easy to assemble, and well documented code.

I did have a little bit of difficulty getting the full Demo code to run, but the bitmap code worked great with a simple upload.