Loading...
  Show Posts
Pages: 1 [2] 3 4 ... 16
16  Using Arduino / Programming Questions / Re: Floats stored in an array? Having troubles on: January 19, 2013, 02:06:04 pm
Paul, I guess I was trying to say that somewhere a int was being converted to a float. So the 11.3 >int = 11> float = 11.00.

Thanks Coding Badly. That worked perfectly.
17  Using Arduino / Programming Questions / Floats stored in an array? Having troubles on: January 19, 2013, 12:35:46 am
When I try to store float variables in an array, I get a int values with a few decimal places after them. The code will work with int variables however, that is not what I need. So where is the number getting truncated?

Code:
#include <TextFinder.h>

TextFinder finder(Serial);
const int NUMBER_OF_FIELDS = 28; // how many comma-separated fields we expect
int fieldIndex = 0; // the current field being received
float values[NUMBER_OF_FIELDS]; // array holding values for all the fields

void setup()
{
Serial.begin(57600); // Initialize serial port to send and receive at 57600 baud
}

void loop()
{
for(fieldIndex = 0; fieldIndex < 28; fieldIndex ++)
{
values[fieldIndex] = finder.getValue(); // get a numeric value
}
Serial.print( fieldIndex);
Serial.println(" fields received:");
for(int i=0; i < fieldIndex; i++)
{
Serial.println(values[i]);
}
fieldIndex = 0; // ready to start over
}

Variables I was using...

Code:
0,0.02,-0.01,9.82,2.0,0,1500,1500,1500,1000,1000,2000,0,0, 1000,1000,1000,1000,0,0,0,0,11.3,0\r\n

Any help would be great! thanks!
18  Using Arduino / Programming Questions / pyFirmata on: November 08, 2012, 09:34:17 pm
I know this is not exactly the right place to ask, But google searches have yielded nothing useful and I don't want to join a Python forum to ask a single question.

I'm trying to install pyFirmata to use with my arduino but I can't get it to install. I'm using Python 3.2.3, have pyserial installed and want to install this:

https://bitbucket.org/tino/pyfirmata/overview

I get the following when trying to install from the command prompt (windows 7 64bit)

Code:
C:\Python32>cd pyfirmata

C:\Python32\pyfirmata>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    import pyfirmata
  File "C:\Python32\pyfirmata\pyfirmata\__init__.py", line 2, in <module>
    from boards import BOARDS
ImportError: No module named boards

C:\Python32\pyfirmata>

Any ideas? I have been trying to get python to talk to the arduino for the last two weeks and have no success with any of the methods!!!!
19  Using Arduino / Networking, Protocols, and Devices / Re: Server haulting after 4 days on: October 11, 2012, 05:11:26 pm
Thanks guys.

Tim, this is a crappy modem/router. There is no way to fix the ip as static... If I use a static IP declared in the code the router refuses to "see" the arduino, although I can ping and access it locally by typing in it's IP via a web browser.

Zoomkat, the arduino is connected to a AT&T/2 Wire Gateway DSL modem/router... AKA garbage. Are you saying that the router would be in charge of the IPs if it was between the modem and arduino?
20  Using Arduino / Networking, Protocols, and Devices / Re: Server haulting after 4 days on: October 10, 2012, 09:15:41 pm
So I changed out some of the obvious stuff that was eating up memory. The code went from 400 bytes free to 630 bytes free.

The code froze after 10 days of running. The free memory never dropped below 630 bytes (that I am aware of).

Something did come to me. I had the code running for weeks at my house. When I installed it in it's permanent location, it is connect through a AT&T gateway which requires that the code request an IP using DHCP rather than pushing one with a IP declared in the code. At my house, I did not use DHCP.

My understanding is that IDE 1.0 had included the DHCP support and there were some improvements.

Do you guys think that this could be the cause? I'm going to try to get the code working in v1.0 or v1.0.1...

Code:
#include <memoryfree.h>
#include <Ethernet.h>
#include <TextFinder.h>
#include "DHT.h"
//#include <avr/pgmspace.h> // for progmem
#include <Dhcp.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>


#define DHTPIN 5
#define DHTTYPE DHT22
//-----------------------------------------------------------------------

// nRF24L01(+) radio attached to SPI and pins 8 & 9
RF24 radio(8,9);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node
const uint16_t other_node = 0;

//-----------------------------------------------------------------------
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE3, 0xCA };//= { 0xC5, 0xA1, 0xDA, 0x00, 0xE3, 0xA3 };
char buffer[8]; // buffer holding the requested page name
Server server(80);
int relayPin = 3;
int switchPin = 2;
int ledPin = 4;
int val5 = 0;
int val = 0;
int stat = 0;
int doorStat;
int doorStat2;
int doorStat3;
int humid;
//int t;
int temp;
int t2 = 0;
int h2 = 0;
const unsigned long interval = 2000;
unsigned long last_sent;

DHT dht(DHTPIN, DHTTYPE);
//--------------------------------------------------------------------------

struct message_t
{
uint16_t temp_reading;
uint16_t humid_reading;
uint16_t doorStat_reading;
message_t(void): temp_reading(), humid_reading(), doorStat_reading() {}
};

struct door_t
{
uint16_t door_reading;
door_t(void): door_reading(0) {}
};
//--------------------------------------------------------------------------

void setup()
{
//        Serial.begin(9600);
while (Dhcp.beginWithDHCP(mac) != 1)
{
delay(15000);
}
delay(1000);

server.begin();
dht.begin();
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
delay(3000);
pinMode(relayPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(relayPin, HIGH);
digitalWrite(switchPin, HIGH);

}

void loop(){

//    Serial.print("freeMemory()=");
//    Serial.println(freeMemory());
 
//-------------------------------------------
humid = dht.readHumidity();
//t = dht.readTemperature();
temp = (dht.readTemperature() * 1.8 + 32);

//----------------------------------------------
// Pump the network regularly
network.update();

// If it's time to send a message, send it!
unsigned long now = millis();
if ( now - last_sent > interval )
{
last_sent = now;


RF24NetworkHeader header(/*to node*/ other_node);
door_t door;
door.door_reading += relayPin;
bool ok = network.write(header,&door,sizeof(door));
relayPin = 3;
}


while ( network.available() )
{
message_t message;
RF24NetworkHeader header;
network.read(header,&message,sizeof(message));
t2 = (message.temp_reading * 1.8 + 32);
h2 = (message.humid_reading);
stat = (message.doorStat_reading);

delay(1000);
}
//----------------------------------------------

Client client = server.available();
if (client) {
TextFinder finder(client );
int type = 0;
while (client.connected()) {
if (client.available()) {
// GET, POST, or HEAD
if(finder.getString("","/", buffer,sizeof(buffer))){
if(strcmp(buffer,"POST ") == 0){
finder.find("\n\r"); // skip to the body
// find string starting with "pin", stop on first blank line
// the POST parameters expected in the form pinDx=Y
// where x is the pin number and Y is 0 for LOW and 1 for HIGH

//------------------------------------------------
while(finder.findUntil("pinD", "\n\r")){
relayPin = finder.getValue(); // the pin number
val = finder.getValue(); // 0 or 1
digitalWrite(relayPin, val);
delay(1000);
digitalWrite(relayPin, HIGH);
}

//------------------------------------------------------------
}

//client.print("<meta http-equiv=\"refresh\" content=\"10\">");
sendHeader(client,"Votto Vines Warehouse");
client.println("<h1><center>Votto Vines</center></h1>");
client.print("<center><IMG SRC='http://24.34.89.0:85/VVwh.jpg' ALT='Image'></center>");
client.println("<br />");
client.println("Warehouse 1 Temperature = "); client.print(temp); client.print("*F");
client.println(", Humidity = "); client.print(humid); client.print("% RH");
client.println("<br />");
client.println("Warehouse 2 Temperature = "); client.print(t2); client.print("*F");
client.println(", Humidity = "); client.print(h2); client.print("% RH");
//-------------------------------------------------------------------------
//Door 1
client.println("<h3>Warehouse 1</h3>");
client.print("<form action='/' method='POST'><p><input type='hidden'name='pinD3'");
client.print(" value='0'><input type='submit' value='Operate Door'/></form>");

client.print("Door is ");
if(doorStat == 1){
client.println("OPEN!");
}
else{
client.println("CLOSED");
}
client.println("<br />");

//--------------------------------------------------------------------------------
//Door 2

client.println("<h3>Warehouse 2</h3>");
client.print("<form action='/' method='POST'><p><input type='hidden'name='pinD4'");
client.print(" value='0'><input type='submit' value='Operate Door'/></form>");

client.print("Door is ");
if(doorStat2 == 1){
client.println("OPEN!");
}
else{
client.println("CLOSED");
}
client.println("<br />");

//--------------------------------------------------------------------------------
//Door 3

client.println("<h3>Warehouse 3</h3>");
client.print("<form action='/' method='POST'><p><input type='hidden'name='pinD5'");
client.print(" value='0'><input type='submit' value='Operate Door'/></form>");

client.print("Door is ");
if(doorStat3 == 1){
client.println("OPEN!");
}
else{
client.println("CLOSED");
client.println("<br />");
client.println("<br />");
client.print("Memory Free =");
client.println(freeMemory());
}
client.println("<br />");

//--------------------------------------------------------------------------------
client.println("</body></html>");
client.stop();
}
break;
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}


val5 = digitalRead(switchPin); // read the input pin
digitalWrite(ledPin, val5); // sets the LED to the button's value
if(val5 == LOW){
doorStat = 0; // low = closed = 1
}
else {
doorStat = 1;
}
//------------------------------------------------------------


//----------------------------------------------

switch(stat)
{
case 0:
doorStat2 = 0;
doorStat3 = 0;
break;
case 10:
doorStat2 = 1;
doorStat3 = 0;
break;
case 01:
doorStat2 = 0;
doorStat3 = 1;
break;
case 11:
doorStat2 = 1;
doorStat3 = 1;
break;
default :
break;
}

}

//----------------------------------------------------------------

void sendHeader(Client client, char *title){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<meta http-equiv=\"refresh\" content=\"10\">");
client.print("<html><head><title>");
client.print(title);
client.println("</title><body>");
}
21  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 02, 2012, 10:40:39 pm
Yeah, slowing it down didn't help... I only tried it in 1.0, it may work in 22 but all of the code I want to upload it 1.0 based.

I just bought this board, so I think it will be going back...
22  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 02, 2012, 10:35:10 pm
Try turning down the upload speed in the boards.txt:
mega2560.upload.speed=57600

My reasoning is that the Mega1280 had an FTDI on it as well.

The board is clearly not auto resetting... unfortunately. Is there a fix for that?
23  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 02, 2012, 09:16:56 pm
Spoke too soon... Still doesn't work with 1.0 IDE.

It works with v 22 but I get two "avrdude: stk500_2_ReceiveMessage(): timeout" before it uploads.
24  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 02, 2012, 08:30:40 pm
Quote
Yes with a very well timed reset button push, I got it to upload once... But that, to me, eas luck and certainly not how it should be

Really?  Try this.  Upload your sketch again with the normal Arduino Mega2560 board with the reset button held down and watch the Tx LED on the FTDI breakout board.  The moment you see *2* flashes on the Tx LED, release the reset button.

Reburned the fuse and bootloader using my USBtinyISP and AVRdude... Appears to be working well now.

Thanks for your help
25  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 02, 2012, 10:38:19 am
Quote
I can bootload through a USBtinyISP. Could I just use the normal Mega 2560 bootloader?

That would be just fine.  Did you try the normal "Arduino Mega2560 ADK" board with your sketch and FTDI?  That one would be the 5v/16MHz board settings.

Yes with a very well timed reset button push, I got it to upload once... But that, to me, eas luck and certainly not how it should be
26  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 02, 2012, 06:56:22 am
Oddly enough, I do not think Sparkfun updated the 5v0 model.  I appears to be an issue a month ago.

Based on my observations, I do not believe that 2560 is bootloaded, so the FTDI will not work (No Blinky on D13).  Do you have another Arduino?  If so, hook up SPI style either by the ICSP headers or Pin headers (I know, you have neither nor).

Then, download the Atmega Board Programmer:
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=11635

And upload to your other Arduino.  When you open the Serial Monitor, you should be able to zap it into shape smiley-wink


I can bootload through a USBtinyISP. Could I just use the normal Mega 2560 bootloader?
27  Using Arduino / Installation & Troubleshooting / Re: Mega Pro 16 mHz/5v not uploading... on: October 01, 2012, 10:53:48 pm
Actually I just noticed that the board files are for the 8mHz/3v3 board... The board.txt lists the Mega Pro as 8mHz...

Can someone point to where I can find the right board files?
28  Using Arduino / Installation & Troubleshooting / Mega Pro 16 mHz/5v not uploading... on: October 01, 2012, 10:24:35 pm
The title says it all really... The board is a sparkfun Mega Pro 5v/16 mHz, adafruit FTDI friend (5volt selected), 1.0 IDE, Windows 7 64bit

I can upload to my Arduino Pro 328 5v/16 mHz using the same FTDI. The board file are the correct ones from sparkfun and the correct board is selected.

When I try to upload the blink sketch, it compiles, states the sketch size and then reads uploading. The board will blink a couple times, FTDI very quickly blinks once and thats it. The IDE never completes the upload. FTDI does not blink. It will stay like this for well over a minute. No error code... Nothing.

I have to exit the program to stop it.

Anyone else have this problem?

BTW, I also tried this with IDE 22 and I got the same thing.

A quick video.

29  Using Arduino / Networking, Protocols, and Devices / Re: Server haulting after 4 days on: September 28, 2012, 08:58:30 am
Thanks for the help gentlemen. I can't use 1.0.1 without porting the libraries for the nRFnetwork and driver.

I will trying to cut down the use of String and see if that will make a difference first, before diving into any porting.
30  Using Arduino / Networking, Protocols, and Devices / Server haulting after 4 days on: September 27, 2012, 10:18:53 pm
I have a garage door opener server that works for 4 or so days and then stops (Firefox times out and says that it took too long). This is not installed at my house, so I thought it was the internet connection. I can ping the address without any loss. The odd thing is that I was not able to access the site a few tries, then it worked but would not reload (or when the meta refresh happened, it would time out) and then I could not access it anymore.
The sketch size is 24188 bytes, is it possible that its running out of memory?

Board is a Uno R2
Sheild is a Yourduino Ethernet shield (Wiznet W5100)
IDE is 22

Here is the code, thanks for any help!

Code:
#include <Ethernet.h>
#include <TextFinder.h>
#include "DHT.h"
#include <avr/pgmspace.h> // for progmem
#include <Dhcp.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>


#define DHTPIN 5
#define DHTTYPE DHT22
//-----------------------------------------------------------------------

// nRF24L01(+) radio attached to SPI and pins 8 & 9
RF24 radio(8,9);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node
const uint16_t other_node = 0;

//-----------------------------------------------------------------------
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE3, 0xCA };//= { 0xC5, 0xA1, 0xDA, 0x00, 0xE3, 0xA3 };
//byte ip[] = { 192, 168, 1, 66 };
//byte gateway[] = { 108, 89, xx, xxx };// 108.89.xx.xxx
char buffer[8]; // buffer holding the requested page name
Server server(80);
int relayPin = 3;
int switchPin = 2;
int ledPin = 4;
int val5 = 0;
int val = 0;
int val2 = 0;
String val3 = 0;
String doorCommand;
int stat = 0;
int doorStat;
int doorStat2;
int doorStat3;
int doorNum;
int door3;
int humid;
int t;
int temp;
int t2 = 0;
int h2 = 0;
const unsigned long interval = 2000;
unsigned long last_sent;

DHT dht(DHTPIN, DHTTYPE);
//--------------------------------------------------------------------------

struct message_t
{
  uint16_t temp_reading;
  uint16_t humid_reading;
  uint16_t doorStat_reading;
  message_t(void): temp_reading(), humid_reading(), doorStat_reading() {}
};

struct door_t
{
  uint16_t door_reading;
  door_t(void): door_reading(0) {}
};
//--------------------------------------------------------------------------

void setup()
{
Serial.begin(9600);
//Ethernet.begin(mac, ip);
  while (Dhcp.beginWithDHCP(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }    
  delay(1000);
  
Serial.println("connecting...");
Serial.println("Begin Ethernet");
server.begin();
Serial.println("Begin Server");
dht.begin();
Serial.println("Begin DHT22");
SPI.begin();
Serial.println("Begin PrintF");
radio.begin();
Serial.println("Begin NRF Radio");
network.begin(/*channel*/ 90, /*node address*/ this_node);
Serial.println("Begin Network");
delay(3000);
Serial.println("Ready");
pinMode(relayPin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(relayPin, HIGH);
digitalWrite(switchPin, HIGH);
//digitalWrite(ledPin, HIGH);

}

void loop(){
//-------------------------------------------
  humid = dht.readHumidity();
  t = dht.readTemperature();
  temp = (t * 1.8 + 32);
  
//----------------------------------------------  
  // Pump the network regularly
  network.update();

  // If it's time to send a message, send it!
  unsigned long now = millis();
  if ( now - last_sent > interval  )
  {
    last_sent = now;

    Serial.print("Sending...");

    RF24NetworkHeader header(/*to node*/ other_node);
    door_t door;
    door.door_reading += relayPin;
    bool ok = network.write(header,&door,sizeof(door));
    if (ok)
      Serial.println("ok.");
    else
      Serial.println("failed.");
      relayPin = 3;
  }
  
  
  while ( network.available() )
  {        
    message_t message;
    RF24NetworkHeader header;
    network.read(header,&message,sizeof(message));
    Serial.print("Received: ");
    t2 = (message.temp_reading * 1.8 + 32);
    h2 = (message.humid_reading);
    stat = (message.doorStat_reading);
    
    Serial.print(t2);
    Serial.print(" , ");
    Serial.println(h2);
    delay(1000);
  }
//----------------------------------------------  
  
Client client = server.available();
if (client) {
TextFinder finder(client );
int type = 0;
while (client.connected()) {
if (client.available()) {
// GET, POST, or HEAD
if(finder.getString("","/", buffer,sizeof(buffer))){
if(strcmp(buffer,"POST ") == 0){
finder.find("\n\r"); // skip to the body
// find string starting with "pin", stop on first blank line
// the POST parameters expected in the form pinDx=Y
// where x is the pin number and Y is 0 for LOW and 1 for HIGH

//------------------------------------------------
while(finder.findUntil("pinD", "\n\r")){
relayPin = finder.getValue(); // the pin number
val = finder.getValue(); // 0 or 1
digitalWrite(relayPin, val);
delay(1000);
digitalWrite(relayPin, HIGH);
}
//------------------------------------------------
//while(finder.findUntil("door", "\n\r")){
//doorNum = finder.getValue(); // the pin number
//val2 = finder.getValue(); // 0 or 1
//}
//-------------------------------------------------

Serial.println(relayPin);
Serial.println(val);
//Serial.println(val3);
//doorCommand = val2 + val3;
//Serial.println(doorCommand);



//------------------------------------------------------------
}

//client.print("<meta http-equiv=\"refresh\" content=\"10\">");
sendHeader(client,"Votto Vines Warehouse");
client.println("<h1><center>Votto Vines</center></h1>");
client.print("<center><IMG SRC='http://24.34.89.0:85/VVwh.jpg' ALT='Image'></center>");
client.println("<br />");
client.println("Warehouse 1 Temperature = "); client.print(temp); client.print("*F");
client.println(", Humidity = "); client.print(humid); client.print("% RH");
client.println("<br />");
client.println("Warehouse 2 Temperature = "); client.print(t2); client.print("*F");
client.println(", Humidity = "); client.print(h2); client.print("% RH");
//-------------------------------------------------------------------------
//Door 1
client.println("<h3>Warehouse 1</h3>");
client.print("<form action='/' method='POST'><p><input type='hidden'name='pinD3'");
client.print(" value='0'><input type='submit' value='Operate Door'/></form>");

client.print("Door is ");
if(doorStat == 1){
client.println("OPEN!");
}
else{
client.println("CLOSED");
}
//client.println("<br />");
//client.println("Warehouse 1 Temperature = "); client.print(temp); client.print("*F");
//client.println(", Humidity = "); client.print(humid); client.print("% RH");
client.println("<br />");

//--------------------------------------------------------------------------------
//Door 2

client.println("<h3>Warehouse 2</h3>");
client.print("<form action='/' method='POST'><p><input type='hidden'name='pinD4'");
client.print(" value='0'><input type='submit' value='Operate Door'/></form>");

client.print("Door is ");
if(doorStat2 == 1){
client.println("OPEN!");
}
else{
client.println("CLOSED");
}
client.println("<br />");

//--------------------------------------------------------------------------------
//Door 3

client.println("<h3>Warehouse 3</h3>");
client.print("<form action='/' method='POST'><p><input type='hidden'name='pinD5'");
client.print(" value='0'><input type='submit' value='Operate Door'/></form>");

client.print("Door is ");
if(doorStat3 == 1){
client.println("OPEN!");
}
else{
client.println("CLOSED");
}
client.println("<br />");

//--------------------------------------------------------------------------------
client.println("</body></html>");
client.stop();
}
break;
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
//Serial.println(temp);
//Serial.println(humid);
//Serial.println(val5);
Serial.println(t2);
Serial.println(h2);


val5 = digitalRead(switchPin);   // read the input pin
digitalWrite(ledPin, val5);    // sets the LED to the button's value
if(val5 == LOW){
  doorStat = 0; // low = closed = 1
}
  else {
    doorStat = 1;
}
//------------------------------------------------------------


//----------------------------------------------

switch(stat) // If node dump reads "1" through blah is node. Need to assign Attic, Outdoor, etc.
{
case 0: // no "0" because we will hard code it in.
doorStat2 = 0;
doorStat3 = 0;
break;
case 10:
doorStat2 = 1;
doorStat3 = 0;
break;
case 01:
doorStat2 = 0;
doorStat3 = 1;
break;
case 11:
doorStat2 = 1;
doorStat3 = 1;
break;
default :
break;
}

}

//----------------------------------------------------------------

void sendHeader(Client client, char *title){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<meta http-equiv=\"refresh\" content=\"10\">");
client.print("<html><head><title>");
client.print(title);
client.println("</title><body>");
}
Pages: 1 [2] 3 4 ... 16