Forum Replies Created
-
AuthorPosts
-
Hi
Further to my last little input I have managed to get the code to compile and run on my MAYFLY with a MB7389 sonar by changing the #include <Sodaq_PcInt_Mod.h> to #include <Sodaq_PcInt_PCINT0.h> and
#include <SoftwareSerialMod.h> to #include <SoftwareSerial_PCINT12.h>
also a few lines down form there I changed
SoftwareSerialMod sonarSerial(11, -1); to SoftwareSerial sonarSerial(11, -1);
It all seems to be working fine after making these changes but wonder if I may be doing it wrong or potentially going to have problems.
Also the way I have it now seems to make the samples get taken every two minutes and I got the impression from the code it would be every minute, am I missing something??Hi
I tried to use this code but it wouldn’t compile due to the #include <Sodaq_PcInt_Mod.h>#include <SoftwareSerialMod.h> libraries not being found. I looked and dowloaded the entire package of libraries from the GITHUB page but still couldn’t find it. any ideas??
I am using GPRSbee Rev.4
Thanks for the link, I was more hoping you could help more with code for making the most of the mayfly when it comes to turning the GPRSbee on off.
I am trying to make the battery measurement code send the data via the GPRSbee.
I want to achieve something along the lines of this.
1. Take a measurement of the battery on A6 and convert it to volts
2. Turn on and initialize a connection using the GPRSbee.
3. Upload the converted measurement via some data portal.
4. Shut down The GPRSbee.
I’m struggling to find a way to make this happen that will compile.
If I work it out I’ll post it but until then any help would be really appreciated.
CheersHi
It’s been a little while since I have had a chance to spend any time on this project but over the last few days I made some time.
Thank you to Danny Waz for your suggestions as they confirmed my suspicions and I have removed the TTL-232 from the Circuit and I am just inverting in code.
I currently have just fudged together all the code that has been provided in the Mayfly software page and have been able to get a file written to the sd card on the Mayfly that contains Sample Number, Battery volts, Temperature from RTC, Millimeters from Maxbotix 7360 Serial( I know this is not the best choice and will change in the next iteration), Year, Month, Day, Time.
I have attached the code below for anyone who may want to use it and to hopefully get some ideas on how to improve it, (I dont really know how to code and cant take any credit for the code good or bad)
Now that I have the data I want coming in,my next goal is to send it using a GPRSbee, any advice or help here would be really appreciated as it’s something I have never had any experience with.
Cheers
RichArduino123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189#include <Wire.h>#include <SPI.h>#include <SD.h>#include "Sodaq_DS3231.h"#include <SoftwareSerial.h>SoftwareSerial mySerial(5, -1,true); // RX, TX, true sets the inverter//Digital pin 12 is the MicroSD slave select pin on the Mayfly#define SD_SS_PIN 12//The data log file#define FILE_NAME "DataLog.txt"//Data header (these lines get written to the beginning of a file when it's created)#define LOGGERNAME "Ultrasonic water level Datalogger"#define DATA_HEADER "Data set includes Sample Number, Battery volts, Temperature,Millimeters, Year, Month, Day, Time"int sampleinterval = 10; //time between samples, in secondsint State8 = LOW;int State9 = LOW;int samplenum = 1; // declare the variable "samplenum" and start with 1int batteryPin = A6; // on the Mayfly board, pin A6 is connected to a resistor divider on the battery inputint batterysenseValue = 0; // variable to store the value coming from the analogRead functionfloat batteryvoltage; // the battery voltage as calculated by the formula belowvoid setup(){//Initialise the serial connectionSerial.begin(57600);pinMode(8, OUTPUT);pinMode(9, OUTPUT);Wire.begin();rtc.begin();mySerial.begin(9600);// set the data rate for the SoftwareSerial port//Initialise log filesetupLogFile();//Echo the data header to the serial connectionSerial.println(DATA_HEADER);}void loop(){String dataRec = createDataRecord();//Save the data record to the log filelogData(dataRec);//Echo the data to the serial connectionSerial.print(dataRec);////////////////////////////////int index = 0;boolean startreading = false;char mm[6];mm[4] = 0;mySerial.flush();while(index < 4){if(mySerial.available()){byte incoming = mySerial.read();if(incoming == 'R') {startreading = true;} else if(startreading) {mm[index++] = incoming;}}}////////////////////////////////////////DateTime now = rtc.now(); //get the current date-timertc.convertTemperature(); //convert current temperature into registersSerial.print(", ");Serial.print(rtc.getTemperature(),2); //read registers and display the temperatureSerial.print(", ");Serial.print(mm);Serial.print(", ");Serial.print(now.year(), DEC);Serial.print(", ");Serial.print(now.month(), DEC);Serial.print(", ");Serial.print(now.date(), DEC);Serial.print(", ");Serial.print(now.hour(), DEC);Serial.print(':');Serial.print(now.minute(), DEC);Serial.print(':');Serial.print(now.second(), DEC);Serial.println();delay(sampleinterval*1000); //multiply by 1000 to convert from milliseconds to seconds}void setupLogFile(){//Initialise the SD cardif (!SD.begin(SD_SS_PIN)){Serial.println("Error: SD card failed to initialise or is missing.");//Hang// while (true);}//Check if the file already existsbool oldFile = SD.exists(FILE_NAME);//Open the file in write modeFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Add header information if the file did not already existif (!oldFile){logFile.println(LOGGERNAME);logFile.println(DATA_HEADER);}//Close the file to save itlogFile.close();}void logData(String rec){//Re-open the fileFile logFile = SD.open(FILE_NAME, FILE_WRITE);//Write the CSV datalogFile.print(rec);////////////////////////////////int index = 0;boolean startreading = false;char mm[6];mm[4] = 0;mySerial.flush();while(index < 4){if(mySerial.available()){byte incoming = mySerial.read();if(incoming == 'R') {startreading = true;} else if(startreading) {mm[index++] = incoming;}}}////////////////////////////////////////DateTime now = rtc.now(); //get the current date-timertc.convertTemperature(); //convert current temperature into registerslogFile.print(", ");logFile.print(rtc.getTemperature(),2); //read registers and display the temperaturelogFile.print(", ");logFile.print(mm);logFile.print(", ");logFile.print(now.year(), DEC);logFile.print(", ");logFile.print(now.month(), DEC);logFile.print(", ");logFile.print(now.date(), DEC);logFile.print(", ");logFile.print(now.hour(), DEC);logFile.print(':');logFile.print(now.minute(), DEC);logFile.print(':');logFile.print(now.second(), DEC);logFile.println();//Close the file to save itlogFile.close();}String createDataRecord(){//Create a String type data record in csv format//SampleNumber, BatteryString data = "";data += samplenum; //creates a string called "data", put in the sample numberdata += ","; //adds a comma between valuesbatterysenseValue = analogRead(batteryPin); // reads the analog voltage on the batteryPin, reported in bitsbatteryvoltage = (3.3/1023.) * 1.47 * batterysenseValue; // converts bits into volts (see batterytest sketch for more info)data += batteryvoltage; //adds the battery voltage to the data stringsamplenum++; //increment the sample numberreturn data;}Hi
As usual Thanks for the support, I have added an RS232-to-TTL converter inline between the board and the mayfly and have had a go with the code you posted with only average success I seemed to be getting every second measurement as a 0 reading and some unreliable repeat-ability.
As I was dubious about the cheap converter I had added to the circuit I decided to try some code that worked well as a software serial option and just turned off the software converter. It seemed to be really good so I’ll go with that. I’ll attach it below for anyone else that may be playing around with these things. I agree the other 2 sensors you mention would be better for the job but I guess I’ll make do with what I have for now.
The example below can be used with a RS232 or TTL just by changing the true/false statement. true if you are using an RS232, false for TTL.Arduino12345678910111213141516171819202122232425262728293031323334353637#include <SoftwareSerial.h>SoftwareSerial mySerial(5, -1,false); // RX, TX, true sets the invertervoid setup(){Serial.begin(57600); // Open serial communications and wait for port to open:mySerial.begin(9600); // set the data rate for the SoftwareSerial portdelay(50);}void loop() {int index = 0;boolean startreading = false;char mm[6];mySerial.flush();while(index < 4){if(mySerial.available()){byte incoming = mySerial.read();if(incoming == 'R') {startreading = true;} else if(startreading) {mm[index++] = incoming;}}}Serial.print("mm: ");Serial.print(mm);Serial.print(" ");Serial.println();//delay(500);}Awesome, I will be one of the first to buy one once they are back in stock.
The 10 11 pin issue is what seems to have made things screwy all along, Now to go find some free pins, using pin 8 seems to make it cycle through the sleep awake about 4 times before getting another sample. It may still be broken but at least it’s different broken 😉Hi
I have just double checked the jumpers I soldered across P2 and P3 as you say to make sure it was not some sort of dry joint problem and all seems well.
The problem I am having it seems is that the software serial is not playing ball after the first sleep, wake up cycle. I have just tried the re allocating sonar onto pin 8 instead of pin 11 and got totally different behavior so will try some more things and give an update. All of the info I can find pointed to pin 11 being free as was pin 8 so I wonder if I am Missing something.Ok so I have the sensor reading well with the code above and I have a sample of the seeduino datalogger that also seems to work but I cant seem to embed one code to the other and have it keep working. it just seems to put the poor little arduino into a coma after taking and writing one sample to the SD card.
Ill attach the datalogger code and hopefully some clever person out there can help.
this code works well on its own.Seeduino Stalker V3 DataloggerArduino123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165//Data logger Demonstration using Seeeduino Stalker v3.0. Logs Battery Voltage every 10 seconds to DATALOG.CSV file//Use this demo code to implement your Datalogger functionality, add additional sensors.//1.Solder P3 and P2 PCB jumper pads//2.Compile and upload the sketch//3.See if everything works fine using Serial Monitor.//4.Remove all Serial port code, recompile the sketch and upload.// This reduces power consumption during battery mode.#include <avr/sleep.h>#include <avr/power.h>#include <avr/power.h>#include <Wire.h>#include <DS1337.h>#include <SPI.h>#include <SD.h>//The following code is taken from sleep.h as Arduino Software v22 (avrgcc) in w32 does not have the latest sleep.h file#define sleep_bod_disable() \{ \uint8_t tempreg; \__asm__ __volatile__(“in %[tempreg], %[mcucr]” “\n\t” \“ori %[tempreg], %[bods_bodse]” “\n\t” \“out %[mcucr], %[tempreg]” “\n\t” \“andi %[tempreg], %[not_bodse]” “\n\t” \“out %[mcucr], %[tempreg]” \: [tempreg] “=&d” (tempreg) \: [mcucr] “I” _SFR_IO_ADDR(MCUCR), \[bods_bodse] “i” (_BV(BODS) | _BV(BODSE)), \[not_bodse] “i” (~_BV(BODSE))); \}DS1337 RTC; //Create RTC object for DS1337 RTCstatic uint8_t prevSecond=0;static DateTime interruptTime;static uint16_t interruptInterval = 10; //Seconds. Change this to suitable value.void setup (){/*Initialize INT0 pin for accepting interrupts */PORTD |= 0x04;DDRD &=~ 0x04;Wire.begin();Serial.begin(57600);analogReference(INTERNAL);RTC.begin();pinMode(4,OUTPUT);//SD Card power control pin. LOW = On, HIGH = OffdigitalWrite(4,LOW); //Power On SD Card.Serial.print(“Load SD card…”);// Check if SD card can be intialized.if (!SD.begin(10)) //Chipselect is on pin 10{Serial.println(“SD Card could not be intialized, or not found”);return;}Serial.println(“SD Card found and initialized.”);attachInterrupt(0, INT0_ISR, LOW); //Only LOW level interrupt can wake up from PWR_DOWNset_sleep_mode(SLEEP_MODE_PWR_DOWN);//Enable Interrupt//RTC.enableInterrupts(EveryMinute); //interrupt at EverySecond, EveryMinute, EveryHour// or thisDateTime start = RTC.now();interruptTime = DateTime(start.get() + interruptInterval); //Add interruptInterval in seconds to start time}void loop (){////////////////////// START : Application or data logging code//////////////////////////////////float voltage;int BatteryValue;BatteryValue = analogRead(A7);voltage = BatteryValue * (1.1 / 1024)* (10+2)/2; //Voltage dividerDateTime now = RTC.now(); //get the current date-timeif((now.second()) != prevSecond ){//print only when there is a changeSerial.print(now.year(), DEC);Serial.print(‘/’);Serial.print(now.month(), DEC);Serial.print(‘/’);Serial.print(now.date(), DEC);Serial.print(‘ ‘);Serial.print(now.hour(), DEC);Serial.print(‘:’);Serial.print(now.minute(), DEC);Serial.print(‘:’);Serial.print(now.second(), DEC);Serial.print(” “);Serial.print(voltage);Serial.print(” V”);Serial.println();}prevSecond = now.second();//|||||||||||||||||||Write to Disk||||||||||||||||||||||||||||||||||File logFile = SD.open(“DATALOG.CSV”, FILE_WRITE);if(logFile) {logFile.print(now.year(), DEC);logFile.print(‘/’);logFile.print(now.month(), DEC);logFile.print(‘/’);logFile.print(now.date(), DEC);logFile.print(‘,’);logFile.print(now.hour(), DEC);logFile.print(‘:’);logFile.print(now.minute(), DEC);logFile.print(‘:’);logFile.print(now.second(), DEC);logFile.print(‘,’);logFile.println(voltage);logFile.close();}//|||||||||||||||||||Write to Disk||||||||||||||||||||||||||||||||||RTC.clearINTStatus(); //This function call is a must to bring /INT pin HIGH after an interrupt.RTC.enableInterrupts(interruptTime.hour(),interruptTime.minute(),interruptTime.second()); // set the interrupt at (h,m,s)attachInterrupt(0, INT0_ISR, LOW); //Enable INT0 interrupt (as ISR disables interrupt). This strategy is required to handle LEVEL triggered interrupt////////////////////////END : Application code //////////////////////////////////\/\/\/\/\/\/\/\/\/\/\/\/Sleep Mode and Power Down routines\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//Power Down routinescli();sleep_enable(); // Set sleep enable bitsleep_bod_disable(); // Disable brown out detection during sleep. Saves more powersei();digitalWrite(4,HIGH); //Power Off SD Card.Serial.println(“\nSleeping”);delay(10); //This delay is required to allow print to complete//Shut down all peripherals like ADC before sleep. Refer Atmega328 manualpower_all_disable(); //This shuts down ADC, TWI, SPI, Timers and USARTsleep_cpu(); // Sleep the CPU as per the mode set earlier(power down)sleep_disable(); // Wakes up sleep and clears enable bit. Before this ISR would have executedpower_all_enable(); //This shuts enables ADC, TWI, SPI, Timers and USARTdelay(10); //This delay is required to allow CPU to stabilizeSerial.println(“Awake from sleep”);digitalWrite(4,LOW); //Power On SD Card.//\/\/\/\/\/\/\/\/\/\/\/\/Sleep Mode and Power Saver routines\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}//Interrupt service routine for external interrupt on INT0 pin conntected to DS1337 /INTvoid INT0_ISR(){//Keep this as short as possible. Possibly avoid using function callsdetachInterrupt(0);interruptTime = DateTime(interruptTime.get() + interruptInterval); //decide the time for next interrupt, configure next interrupt}Hi
Thanks for the help, I really appreciate the well commented code as I really have no idea whats going on without it.
I tried your code and perhaps I was having data issues because Of something I did or because of a different sensor but I was getting quite a few out of sync readings that would throw a spanner in the works for using the data later.
I have had really good data coming from the code attached here, hopefully between the two options someone may get some benefit out of these options.Maxbotix7360 software serial mmArduino12345678910111213141516171819202122232425262728293031323334// RX, TX, true sets the invertervoid setup(){// Open serial communications and wait for port to open:Serial.begin(9600);// set the data rate for the SoftwareSerial portmySerial.begin(9600);delay(50);}void loop() {int index = 0;boolean startreading = false;char mm[6];mySerial.flush();while(index < 4){if(mySerial.available()){byte incoming = mySerial.read();if(incoming == 'R') {startreading = true;} else if(startreading) {mm[index++] = incoming;}}}Serial.print("mm: ");Serial.print(mm);Serial.print(" ");Serial.println();//delay(500);} -
AuthorPosts