Eureka!! It works!
It was the wiring, your last post made me recheck how I had wired this initially.
Just need to change (9, 10) to (10, 9)!
Thanks for your patience, and I also learned something new "data type structures".
Sometimes the journey is more exciting than reaching the destination!
Phase 2 will be to include this in a network of multiple sensors using the RF24network libraries.
That should be the easy part, as the basic groundwork is complete.
Cool, glad you got it working!
Welcome to the world of OOP in Arduino! 🙂
I didn't realise that OOP was an option in the world of Arduino.
It is something I have used before in both Python and Java programming, but I was under the illusion that C++ in the Arduino world was limited to the instruction set detailed on the original Arduino Language Reference website.
What a mistake?? ? ? ?
I did start a thread #post-4070 several months ago, on the subject of creating libraries, but it received very little resonance. The reason this interested me was that I quite like to read and write to registers without relying on third-party libraries, I feel much happier addressing them myself. But when the next piece of junk arrived from China I just got distracted.
Here are my first and last feeble attempts at it. Of no particular use, but I was just finding out what libraries were all about and how to employ them myself. Even at my age ?, I am always keen to learn something new!
Cool... I'll check out that thread soon enough.
I have missed many threads, because I hadn't been around for a while, since I helped Bill with some initial forum testing, but as of recently, hoping to see and participate a lot more.
OK, I had a quick look, but you haven't included all of the files in your last post there... it's missing the implementation file for the class, or is that the part you're having trouble with? Have any of the recent examples I posted helped? If not, let me know what problems you're having and I will try to help.
OK, I had a quick look, but you haven't included all of the files in your last post there... it's missing the implementation file for the class, or is that the part you're having trouble with? Have any of the recent examples I posted helped? If not, let me know what problems you're having and I will try to help.
I wasn't having any troubles, they seemed to work "as is"!
I thought though, that I only needed a .cpp and .h files for the libraries to work. What exactly am I missing?
Ok, so that code you embedded directly in your post, is that what you weren't able to attach? Is that what you meant? No, .cpp and .h files are all you need.
Ok, so that code you embedded directly in your post, is that what you weren't able to attach? Is that what you meant? No, .cpp and .h files are all you need.
I think we are talking at cross purposes here!
The archive.zip file was just a demonstration of my first feeble attempt at building my own library. Nothing more, nothing less. Only posted for possible positive or negative criticism. ?
No, I was talking about your other post... haven't looked at the .zip file yet 🙂
Anyway, here's how you could have written the code in your old post:
CostomLed.ino
#include "Led.h" #define ledPin 13 pugwash::Led Led1(ledPin, OUTPUT); void setup() { Serial.begin(9600); } void loop() { Led1.ledOn(); delay(1000); Led1.ledOff(); delay(1000); }
Led.h
#ifndef PUGWASH_LED_H #define PUGWASH_LED_H #include "Arduino.h" namespace pugwash { class Led { private: byte LedPin; public: Led(byte pin, byte mode); void ledOn(); void ledOff(); }; } #endif
Led.cpp
#include "Led.h" namespace pugwash { Led::Led(byte pin, byte mode) : LedPin(pin) { pinMode(LedPin, mode); } void Led::ledOn() { digitalWrite(LedPin, HIGH); } void Led::ledOff() { digitalWrite(LedPin, LOW); } }
The reason for the namespace is so your personal library names do not clash or interfere with any other library names, because a namespace introduces a new scope, so all libraries should have their own distinct namespace.
I hope you enjoyed your first day in the new job. Me, the last time I set an alarm clock was last January or February, 48 years of work was enough!!
Now I need to pick your brains again:
typedef struct Message{ float temperature; float pressure; float altitude; float humidity; byte checksum; }bme280data; bme280data myObject; // declare the message object
So I have got this object "myObject". It is 17 bytes long and I need the first 16 bytes in an array to calculate the checksum. I tried for several hours but to no avail. Perhaps you can help. It is obviously possible, as somewhere in the RF24 library there is a routine that extracts the bytes to send them sequentially to the receiver.
As for the BME280 module. The vendors claim an altitude accuracy of +/- 1 metre. I find this a bit far fetched (understatement). I have had this running for about 48 hours, although the air pressure reading is pretty accurate (compared to local weather station), I now find myself at an altitude of 179m above mean sea level and I know I am actually only about 25m above.
Back in my youth, when I flew in Chipmunks with the ATC, the pilot always zeroed out his altimeter before take-off. Therefore I think I need to chain two of these modules together.
One module with SEALEVELPRESSURE_HPA set to 1013 hPa, and the other module with SEALEVELPRESSURE_HPA set to the actual air pressure that I am getting from module 1, compensated for 25m of altitude.
Any thoughts welcome!!