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 }
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:
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!!!!
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?
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...
// 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;
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.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; } //------------------------------------------------------------
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.
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).
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.
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
// 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;
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 //} //-------------------------------------------------
//-------------------------------------------------------------------------------- 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; }