Show Posts
|
|
Pages: [1] 2
|
|
2
|
Using Arduino / Programming Questions / Re: Sending int variable over virtualwire?
|
on: March 07, 2011, 07:38:14 pm
|
After working with it a little, I was able to get it to send it, and constantly work. I was recieving capital F's for "70" degrees when I tried it. I found out that I only needed to do this: msg[0] = byte(temp); msg[1] = '\0';
vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); but needed to end it with the msg[1] = '\0'; to end the array My main question is how to decode this on the receiving end, and put into an int form? Thanks for your time
|
|
|
|
|
3
|
Using Arduino / Programming Questions / Re: Sending int variable over virtualwire?
|
on: March 07, 2011, 01:56:26 am
|
|
Hmm, i dont exactly understand the code that much. When doing this, would i send the msg along with the [ 0 ], or just msg by itself? What is the 0xFF doing in this particular case? So far i tried this, but my main problem is defining msg. How would i do this?
Im pretty new to C++, so sorry if i take a minute...
If possible, please show the exact code Thanks for the help
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: Sending int variable over virtualwire?
|
on: March 07, 2011, 01:01:10 am
|
Thanks for the reply, I am not sure i completely understand the process of doing this, i tried this however i still had the same error message. I also tried combining it with the code, and even removing the original float *msg = (temp); but then it said that msg was not defined. This is what I did in the code originally: const char *msgT = "t"; // this is your message to send vw_send((uint8_t *)msgT, strlen(msgT)); vw_wait_tx(); float *msg = (temp); msg[0]=temp; vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); /*float *msg = (temp); int tempC1 = (int)temp; int tempC2 = (int)(temp - tempC1) * 100; // For two decimal points char msg[24]; sprintf(msg, "%i.%i", tempC1,tempC2); vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx();*/ What would i need to change to make this work? Would i still need the part i commented out? Thanks
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Sending int variable over virtualwire?
|
on: March 06, 2011, 11:24:46 pm
|
Hi all, Ive been looking at this post here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279775453 and was wondering how to pull this off and send values over virtualwire. However in this example they are using a float value and when I try to do this in the code that i'm using, i recieve the message "invalid conversion from 'int' to 'float*'. How do i fix this? Here is the code that i am using: int val; int val2; int temp; int humid; sendCommandSHT(gTempCmd, theDataPin, theClockPin); waitForResultSHT(theDataPin); val = getData16SHT(theDataPin, theClockPin); skipCrcSHT(theDataPin, theClockPin); temp = -40.0 + 0.018 * (float)val; Serial.print("t"); Serial.print(temp, DEC); const char *msgT = "t"; // this is your message to send vw_send((uint8_t *)msgT, strlen(msgT)); vw_wait_tx(); float *msg = (temp); int tempC1 = (int)temp; int tempC2 = (int)(temp - tempC1) * 100; // For two decimal points char msg[24]; sprintf(msg, "%i.%i", tempC1,tempC2); vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx();
delay(400); Thanks for your time.
|
|
|
|
|
9
|
Using Arduino / General Electronics / Arduino + SPDT Relay
|
on: February 18, 2011, 11:59:44 pm
|
|
Hello all, I have a very simple question (im pretty new), I am using an Arduino Duemilanove connected to an spdt relay (thats controlling a 12v motor), turning it on for about 30 second periods or less. Im not using PWM, just simply turning it on and off. What components do i need in order to keep it working, but not fry the Arduino, or is it okay by itself? Also, what would i need to protect it when using LEDs? Would this be a resistor? If so, what type?
Thanks for the help
|
|
|
|
|
10
|
Using Arduino / Networking, Protocols, and Devices / Re: Serial Communication without computer?
|
on: January 28, 2011, 01:15:00 pm
|
|
I tried to use that code and it didn't seem to do anything (rx/tx lights not on, or serial output). However I did try a code (i forget where from) and it worked without being connected to my computer. What code would i be able to use with just the arduinos+transmitters/recievers (no buttons or anything) just to see if it works?
Thanks
|
|
|
|
|
11
|
Using Arduino / Networking, Protocols, and Devices / Re: Serial Communication without computer?
|
on: January 27, 2011, 12:07:29 am
|
|
I am pretty new to arduino, and no i do not use "shiftOuts." However, they are not talking to each other, one is sending the other the data, and it takes it from there, but does not send anything back. (Transmitter --> Reciever) I am using Serial.prints, so how would i fix that?
Thanks for the help
|
|
|
|
|
15
|
Using Arduino / Networking, Protocols, and Devices / Re: Serial Communication without computer?
|
on: January 25, 2011, 11:46:32 pm
|
okay for the Duemilanove i am using this - int gTempCmd = 0b00000011; int gHumidCmd = 0b00000101;
int shiftIn(int dataPin, int clockPin, int numBits) { int ret = 0; int i;
for (i=0; i<numBits; ++i) { digitalWrite(clockPin, HIGH); delay(10); // I don't know why I need this, but without it I don't get my 8 lsb of temp ret = ret*2 + digitalRead(dataPin); digitalWrite(clockPin, LOW); }
return(ret); }
void sendCommandSHT(int command, int dataPin, int clockPin) { int ack;
// Transmission Start pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); digitalWrite(dataPin, HIGH); digitalWrite(clockPin, HIGH); digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW); digitalWrite(clockPin, HIGH); digitalWrite(dataPin, HIGH); digitalWrite(clockPin, LOW);
// The command (3 msb are address and must be 000, and last 5 bits are command) shiftOut(dataPin, clockPin, MSBFIRST, command);
// Verify we get the coorect ack digitalWrite(clockPin, HIGH); pinMode(dataPin, INPUT); ack = digitalRead(dataPin); if (ack != LOW) Serial.println("Ack Error 0"); digitalWrite(clockPin, LOW); ack = digitalRead(dataPin); if (ack != HIGH) Serial.println("Ack Error 1"); }
void waitForResultSHT(int dataPin) { int i; int ack;
pinMode(dataPin, INPUT);
for(i= 0; i < 100; ++i) { delay(10); ack = digitalRead(dataPin);
if (ack == LOW) break; }
if (ack == HIGH) Serial.println("Ack Error 2"); }
int getData16SHT(int dataPin, int clockPin) { int val;
// Get the most significant bits pinMode(dataPin, INPUT); pinMode(clockPin, OUTPUT); val = shiftIn(dataPin, clockPin, 8); val *= 256;
// Send the required ack pinMode(dataPin, OUTPUT); digitalWrite(dataPin, HIGH); digitalWrite(dataPin, LOW); digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW);
// Get the lest significant bits pinMode(dataPin, INPUT); val |= shiftIn(dataPin, clockPin, 8);
return val; }
void skipCrcSHT(int dataPin, int clockPin) { // Skip acknowledge to end trans (no CRC) pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT);
digitalWrite(dataPin, HIGH); digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); }
void setup() { Serial.begin(2400); // open serial }
void loop() { int theDataPin = 10; int theClockPin = 11; char cmd = 0; int ack;
int val; int temp;
sendCommandSHT(gTempCmd, theDataPin, theClockPin); waitForResultSHT(theDataPin); val = getData16SHT(theDataPin, theClockPin); skipCrcSHT(theDataPin, theClockPin); temp = -40.0 + 0.018 * (float)val; Serial.print("t"); Serial.println(temp, HEX); }
And for the Mega I am using this (just to simply receive it) - int incomingByte = 0; // for incomi boolean temp = false; boolean readFirst = false; boolean readSecond = false; int readValue = -1;
void setup() { Serial.begin(2400); // opens serial port, sets data rate to 9600 bps }
void loop() { // send data only when you receive data: if (Serial.available() > 0) { incomingByte = Serial.read(); // read the incoming byte if (!readFirst) { // if we haven't read the first byte of the triad, then we are now char incomingChar = (char) incomingByte; // make it a character Serial.println(incomingChar); // print it to serial if (incomingChar == 't') { // if it's 't' temp = true; // then we are reading a temperature } else { // otherwise, it's an 'h' temp = false; // and we don't have temperature } readFirst = true; // we have read in the first of a triad } else if (!readSecond) { // if we haven't read the second byte, then we are now readValue = (incomingByte - 48) * 10; // so make the readValue the ASCII digit it represents * 10 readSecond = true; // and mark that we read the second byte } else { // we must be reading the third byte readValue += (incomingByte - 48); // so add in the next ASCII digit processData(); // process the data readFirst = false; // and clear both flags readSecond = false; // so we read another value } } }
void processData() { // do something with the data }
Thanks
|
|
|
|
|