Show Posts
|
|
Pages: [1] 2 3 ... 25
|
|
3
|
Using Arduino / Programming Questions / Re: Using SoftwareSerial inside a library - Arduino 1.02
|
on: December 05, 2012, 04:58:00 pm
|
made a typo which didnt help, in the Library::Library() line. Errors I get now are: Library.cpp: In constructor 'Library::Library()': Library.cpp:13: error: no matching function for call to 'SoftwareSerial::SoftwareSerial()' SoftwareSerial.h:83: note: candidates are: SoftwareSerial::SoftwareSerial(uint8_t, uint8_t, bool) SoftwareSerial.h:48: note: SoftwareSerial::SoftwareSerial(const SoftwareSerial&) Library.cpp:15: error: no match for call to '(SoftwareSerial) (int, int)' Line 13 is: Library::Library() //Line 13 { mySerial(2, 3); mySerial.begin(9600); }
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: Using SoftwareSerial inside a library - Arduino 1.02
|
on: December 05, 2012, 04:27:35 pm
|
Sorry so that goes in the cpp file? So the h file and the sketch looks ok...? But the cpp file needs to be this?: #include "Library.h" #include "Arduino.h" // for Arduino 1.0
Library::Library() { mySerial(2,3); mySerial.begin(9600); } not sure sure what Library::Library() , mySerial(2,3) means... is that a single line I put in place of the Library::Library() ? Im getting a truck load of errors... error: ISO C++ forbids declaration of 'Library' with no type error: no 'int Library::Library()' member function declared in class 'Library' etc Sorry can you spell it out for me... Thanks
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Re: Using SoftwareSerial inside a library - Arduino 1.02
|
on: December 05, 2012, 02:54:24 pm
|
Thanks guys, still cant get it working. Here is a better layout of what I have currently, if you can point out what I have done wrong I would appreciate it. I have little knowledge at all of C++. So as mentioned above, I am just trying to get my library to be able to use the Software Serial, my sketch does not need access to it. But if it has to, then that is fine... Library.h File #ifndef Library_h #define Library_h #include "Arduino.h" // for Arduino 1.0
#include <SoftwareSerial.h> //Software Serial Library
class Library { public: //Bunch of stuff here private: SoftwareSerial mySerial; }
Library.cpp File #include "Library.h" #include "Arduino.h" // for Arduino 1.0
mySerial = SoftwareSerial(2, 3); //Tried various combinations, in and out of the constructor, but similar results.
Library::Library() { mySerial.begin(9600); }
My Sketch #include <SoftwareSerial.h> #include <Library.h>
Library Library;
void Setup() { }
void loop() { }
The above might not be the best combination I have tried, but is one of them. Really not sure what I am doing, so help would be apprecaited. Thanks J
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Re: Using SoftwareSerial inside a library - Arduino 1.02
|
on: December 05, 2012, 02:47:05 am
|
|
Ok, I have added that to the main sketch too - thought I had tried that. Now get:
error: a call to a constructor cannot appear in a constant-expression error: ISO C++ forbids initialization of member 'mySerial' error: making 'mySerial' static error: invalid in-class initialization of static data member of non-integral type 'SoftwareSerial'
All pointing to the same line of code in the .h file
private: SoftwareSerial mySerial = SoftwareSerial(2, 3);
In that post it suggested I cant do SoftwareSerial mySerial = SoftwareSerial(2, 3); there, and that I just do SoftwareSerial mySerial; ? And then have to call mySerial(2,3); somewhere else?
Will keep trying, but I must just be stupid.
|
|
|
|
|
7
|
Using Arduino / Programming Questions / Using SoftwareSerial inside a library - Arduino 1.02
|
on: December 05, 2012, 01:07:15 am
|
Hello, Just after a bit of help please. Attempting to write a library. The Library is going to use the SoftwareSerial library that comes with the Arduino IDE. The Sketch itself doesnt need access to the Software Serial port, just the library. Ive tried a few things, but so far I get: error: 'SoftwareSerial' does not name a type in the library.h file I have the #include <SoftwareSerial.h> in the library.cpp file I have tried a few things, but same result. SoftwareSerial mySerial(2, 3). And then it uses mySerial.write() etc throughout. And in the sketch I have nothing, as the sketch I dont need to reference it. I tried the SoftwareSerial mySerial; in the header file, and then myLibrary::mySerial(2,3) in the cpp file... but whatever combination I use I seem to get the same result. Also SoftwareSerial mySerial = SoftwareSerial(2,3); If a better code example is required, I can whip one up, but if someone could help me understand what needs to go where, so the library can use the Software Serial, that would be apprecaited. I clearly dont know what I am doing. So far I have been following http://arduino.cc/en/Hacking/LibraryTutorial but I havent found anything from searching that has helped yet. I did find this, however obviously havent understood correctly as I am still having problems, http://arduino.cc/forum/index.php/topic,114761.0.html Any help would be appreciated Regards J
|
|
|
|
|
11
|
Using Arduino / Programming Questions / http://arduino.cc/forum/index.php/topic,45445.0.html
|
on: November 09, 2012, 02:57:30 am
|
Hello I had a PM from a user who couldnt reply to my original topic, due to the forum change I suspect, my original thread was here http://arduino.cc/forum/index.php/topic,45445.0.htmlHe asked me how you would go about sending an array of 6 floats over I2C. I havent done it before, only to the extent of what the post shows, 2 single floats, using two unions, sending the bytes etc. I attempted to write him some code to try, but he said it didnt work. Code is as follows. It compiled, but I did not test it. He said the following was received: Float 1 Value: 740733.56 Float 2 Value: 1234.12 Float 3 Value: 12345.56 Float 4 Value: 0.00 Float 5 Value: 0.00 Float 6 Value: 0.00 Master Arduino: #include <Wire.h>
byte data[24]; float floatData[6]; long lastSerialPrint = 0;
void setup() { Serial.begin(9600); Wire.begin(); }
void loop() { Wire.beginTransmission(2); Wire.requestFrom(2, 24); // request 24 bytes from slave device #2 if(Wire.available()) { int i = 0; while(Wire.available()) // slave may send less than requested { data[i] = Wire.read(); // receive a byte as character i = i + 1; } //A union datatypes makes the byte and float elements share the same piece of memory, which enables conversion from a byte array to a float possible union Float1_tag {byte Float1_b[4]; float Float1_fval;} Float1_Union; //Float 1 Float1_Union.Float1_b[0] = data[0]; Float1_Union.Float1_b[1] = data[1]; Float1_Union.Float1_b[2] = data[2]; Float1_Union.Float1_b[3] = data[3]; floatData[0] = Float1_Union.Float1_fval * 60; union Float2_tag {byte Float2_b[4]; float Float2_fval;} Float2_Union; //Float 2 Float2_Union.Float2_b[0] = data[4]; Float2_Union.Float2_b[1] = data[5]; Float2_Union.Float2_b[2] = data[6]; Float2_Union.Float2_b[3] = data[7]; floatData[1] = Float2_Union.Float2_fval; union Float3_tag {byte Float3_b[4]; float Float3_fval;} Float3_Union; //Float 3 Float3_Union.Float3_b[0] = data[8]; Float3_Union.Float3_b[1] = data[9]; Float3_Union.Float3_b[2] = data[10]; Float3_Union.Float3_b[3] = data[11]; floatData[2] = Float3_Union.Float3_fval; union Float4_tag {byte Float4_b[4]; float Float4_fval;} Float4_Union; //Float 4 Float4_Union.Float4_b[0] = data[12]; Float4_Union.Float4_b[1] = data[13]; Float4_Union.Float4_b[2] = data[14]; Float4_Union.Float4_b[3] = data[15]; floatData[3] = Float4_Union.Float4_fval; union Float5_tag {byte Float5_b[4]; float Float5_fval;} Float5_Union; //Float 5 Float5_Union.Float5_b[0] = data[16]; Float5_Union.Float5_b[1] = data[17]; Float5_Union.Float5_b[2] = data[18]; Float5_Union.Float5_b[3] = data[19]; floatData[4] = Float5_Union.Float5_fval; union Float6_tag {byte Float6_b[4]; float Float6_fval;} Float6_Union; //Float 6 Float6_Union.Float6_b[0] = data[20]; Float6_Union.Float6_b[1] = data[21]; Float6_Union.Float6_b[2] = data[22]; Float6_Union.Float6_b[3] = data[23]; floatData[5] = Float6_Union.Float6_fval; } Wire.endTransmission(); if(millis() > lastSerialPrint + 1000) //Like the Blink without delay example, true once a second { Serial.print("Float 1 Value: "); Serial.println(floatData[0]); Serial.print("Float 2 Value: "); Serial.println(floatData[1]); Serial.print("Float 3 Value: "); Serial.println(floatData[2]); Serial.print("Float 4 Value: "); Serial.println(floatData[3]); Serial.print("Float 5 Value: "); Serial.println(floatData[4]); Serial.print("Float 6 Value: "); Serial.println(floatData[5]); lastSerialPrint = millis(); //Snapshot of when this happened, in milli seconds } } Slave Arduino: #include <Wire.h>
volatile byte* Float1ArrayPtr; //Float 1 Array Pointer (series of bytes, 4 bytes each float) volatile byte* Float2ArrayPtr; //Float 2 Array Pointer (series of bytes, 4 bytes each float) volatile byte* Float3ArrayPtr; //Float 3 Array Pointer (series of bytes, 4 bytes each float) volatile byte* Float4ArrayPtr; //Float 4 Array Pointer (series of bytes, 4 bytes each float) volatile byte* Float5ArrayPtr; //Float 5 Array Pointer (series of bytes, 4 bytes each float) volatile byte* Float6ArrayPtr; //Float 6 Array Pointer (series of bytes, 4 bytes each float) int Address = 2; //This slave is address number 2 float floatData[6]; //Your float array
void setup() { Wire.begin(Address); Wire.onRequest(requestEvent); // register event }
void loop() { //Your code with putting values into your float array floatData[0] = 12345.56; //your code here floatData[1] = 1234.12; //your code here floatData[2] = 12345.56; //your code here floatData[3] = 1234.12; //your code here floatData[4] = 12345.56; //your code here floatData[5] = 1234.12; //your code here }
// function that executes whenever data is requested by master // this function is registered as an event, see setup() void requestEvent() { byte* Data; Float1ArrayPtr = (byte*) &floatData[0]; Data[0] = Float1ArrayPtr[0]; Data[1] = Float1ArrayPtr[1]; Data[2] = Float1ArrayPtr[2]; Data[3] = Float1ArrayPtr[3]; Float2ArrayPtr = (byte*) &floatData[1]; Data[4] = Float2ArrayPtr[0]; Data[5] = Float2ArrayPtr[1]; Data[6] = Float2ArrayPtr[2]; Data[7] = Float2ArrayPtr[3]; Float3ArrayPtr = (byte*) &floatData[2]; Data[8] = Float3ArrayPtr[0]; Data[9] = Float3ArrayPtr[1]; Data[10] = Float3ArrayPtr[2]; Data[11] = Float3ArrayPtr[3]; Float4ArrayPtr = (byte*) &floatData[3]; Data[12] = Float4ArrayPtr[0]; Data[13] = Float4ArrayPtr[1]; Data[14] = Float4ArrayPtr[2]; Data[15] = Float4ArrayPtr[3]; Float5ArrayPtr = (byte*) &floatData[4]; Data[16] = Float5ArrayPtr[0]; Data[17] = Float5ArrayPtr[1]; Data[18] = Float5ArrayPtr[2]; Data[19] = Float5ArrayPtr[3]; Float6ArrayPtr = (byte*) &floatData[5]; Data[20] = Float6ArrayPtr[0]; Data[21] = Float6ArrayPtr[1]; Data[22] = Float6ArrayPtr[2]; Data[23] = Float6ArrayPtr[3]; Wire.write(Data,24); //Send the 24 bytes (6 floats) } If anyone has any advice to help him, it would be appreciated. I have PM'ed him back with the link to this thread. Im not suggesting the way I wrote it is the best method by any means, but was the only way I knew that I had tried and had worked, but never to the extent of sending 6 floats. Cheers J
|
|
|
|
|
12
|
Using Arduino / Programming Questions / Re: Read filename from SD card, store to a string
|
on: November 06, 2012, 05:24:34 pm
|
|
I did say in post #1 I am using the SDFAT library, not the SD library. Also posted pieces of the SDFAT functions. I didnt even know there was a SD library 'wrapper' or whatever its called to be honest.
Tried implmenting the SD library instead, but its not compiling. Looks like the 2012 SDFAT library I am using is not quite the same as the 2009 SDFAT library which is part of the SD library included with Arduino 1.01
No luck so far, will keep trying.
|
|
|
|
|
15
|
Using Arduino / Programming Questions / Re: Read filename from SD card, store to a string
|
on: November 06, 2012, 03:37:44 pm
|
|
I appreaciate that, but I have posted what I tried.
I didnt just go and write code I know wouldnt work, I tried looking at the sdfat library first to find a function which was suitable, but I havent found one that I understand how to use, hence the post...
There is no more code to post as I havent written any....
Im confused why this is so much of an issue... should I be trying stuff I have no idea if it will work, or should I be reading the library to find something suitable first. I thought the 2nd option was the valid option here...
Sorry if I have offended anyone, but I just havent written non working code, would like to find a viable solution from the library first...
|
|
|
|
|