New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having trouble with the sample code... #170
Comments
Sorry to hear you're running into problems! Here's what I had to do to get the example working. Hope this sheds some light on where you might be running into a problem:
The example works fine, repeatably, for me. Here's a bunch of questions that will help us figuring out what may be going wrong:
|
Thanks very much Nathan. I'll give this a try and let you know what I find. I'm running mine on an Arduino Nano V3, but I can also try it on an Uno. I'm almost certain I'm already running at 9600 baud. Meanwhile, let me take a crack at your questions...
An Arduino Nano V3. But I will try an Uno as well if need be
9600
5V. But I also tried using a Sparkfun Logic Level Converter as I assumed that could be the problem - rather than the reading itself. I later realized that couldn't be the problem because I get perfect results when asking for things like OpenLog status. The problem only occurs when I'm actually trying to read data from the SD card.
No. But I have tried more than one OpenLog board - and your level-1 tech support folks got the same faulty results as me when they ran it on their hardware. I will try a reset.
No. Thanks again. I'll give this another try, making sure to follow your tips, and let you know how it goes. Best regards. Rick Cavallaro
|
Thanks for continuing to figure this out! Only when reading data.... How odd. I'll see if I can learn anything from the setup that tech support was running. There is nothing outlandish about your setup. I've never used a nano but should be fine. You don't need a level converter. The OpenLog is quite happy at 3.3V or 5V.
What do you mean by it? The Nano or OpenLog. What I'm getting at is OpenLog might be working just fine and the Nano might be having parsing issues.
|
Nathan, Thanks so much for helping with this. I watched your Google talk just the other day and loved it. I love what you guys are doing at Sparkfun. I followed your directions carefully and it did in fact work just fine. But I remembered that it seemed to work OK for me when the file was quite small and/or had short lines. So I made three changes to the sketch:
I've attached a zip file that includes the modified sketch and shows the results. When using the Arduino Nano to read from OpenLog and echo the data to the serial monitor you can see that it gets quite garbled. But when I read the SD card on my laptop you can see that it's actually logging perfectly every time.
I sent the "?" to OpenLog at the prompt and sent the resulting text to the serial monitor. It appears to be firmware version 3.11. As you can see, this also got pretty garbled. OpenLog v3.11
I'm not sure how to answer that. I only communicate with OpenLog via the Arduino Nano. So I'm not able to tell whether the Arduino or OpenLog is at fault. I only know that I when I remove the SD card and read it on my laptop I always find the expected text without errors.
I have in the past thrown data at OpenLog for normal logging. When I put the card in my laptop the data appears to be fine. The only way I've tried to read the text back with OpenLog is via the sketch we're now discussing.
I'm not getting any compile or run-time errors. The nature of the errors is simply that the text read back from the card (as displayed on the serial monitor through the Arduino dev environment) is garbled. But the data on the card itself is not garbled.
That may in fact be the problem. But that is exactly what I'm hoping to do. My hope is to read back the logged data on the card and send it to my laptop via bluetooth (since the whole thing will be in a waterproof enclosure). I presume I will run into the same problem there - yes?
Thanks. I just checked it out. It contains good information but doesn't seem to shed any light on the lost characters. I suspect you've hit on the problem with Serial.print() taking too much time. But that seems like one of the few things you can do with the data when reading back from the card. Is there a work-around? Maybe I could read a line from the card, print that to Serial, read the next line, etc.? Thanks again for your help. Best regards. Rick Cavallaro
|
Hi Rick, Your example output is really garbled in some funky ways - makes me believe you may have some array indexing errors in your Nano code. I didn't see a zip file? Maybe try again. I'd like to have a look at your code. Excellent feedback, I think I've got a good grasp of what's going on. I highly recommend an FTDI Basic and a crossover board. This will allow you to connect directly to the OpenLog so that you can configure it, throw lots of data at it, read lots of data back and see what exactly the OpenLog is doing. The fact that OpenLog is recording everything correctly means the OpenLog is performing as expected. I'm really starting to believe the error is stemming from the Nano. Here's the problem: Reading serial from the OpenLog via software serial takes a large amount of processor overhead. Let's say the Nano is spending 98% of its time monitoring the incoming serial characters from the OpenLog. The Nano then has to spend time sending out those characters over serial. Every time the Nano reports something that is time not spent listening to the OpenLog and that's when characters get missed. For example, when the Nano is printing this
The Nano is not monitoring the incoming serial from the OpenLog so when the Nano gets done printing stuff it goes back to listening and misses a few dozen incoming characters from the OpenLog. The solution is to print less and listen more. The example code mentions this a few times. And as a final question (sorry!) - what is your overall application? Most people use OpenLog for logging. Reading back from OpenLog is do-able but requires more processor power. |
Thanks again for the response.
I wondered that as well - but I really haven't changed any of that from the example code you provided. I just now repeated the problem using your example code with only a single change. I added "fileNumber = 110;". This way it always writes to and appends to "log110.txt" rather than creating a random file. Another really inexplicable thing is that your example code doesn't work for me until I add that line. It writes the file, but it gets stuck trying to open the file to read. Without my change I get this on the serial monitor in the Arduino dev env.:
OpenLog online
Here's the code I just ran. It's your example with the one line change I mentioned: /*
I like that idea. I will probably try that. I think the other thing I'll try is reading one byte at a time from OpenLog using "readBytes()" so that it's not trying to read and print at the same time. I presume that "serial.read()" is telling openLog to stream data - and the timing errors you mentioned have the Arduino failing to keep up. Is this right?
<< I suspect you're right. I just now changed the code further so that it no longer appends to the file and it no longer prints the file contents to the Arduino dev. env. serial monitor. It simply counts the bytes in the file and reports the final number to the serial monitor. It consistently reports reading 428 bytes. This suggests to me that it's not making errors. When I read the file on my laptop it shows as 504 bytes, but I'm guessing that's somehow counting the difference between a and a or something like that.
I'm making a jump height meter for kitesurfing. It will use the Arduino with the MS5611 to read altitude. It will log jumps to openLog, and it will then stream the data to the laptop via bluetooth. This lets me put the whole thing in a completely water-tight bladder with no wires or anything hanging out. I have used it in the past in exactly the way you describe. It worked great. We developed a wind powered vehicle that goes faster than the wind both directly upwind and directly downwind. We had to log a lot of wind and GPS data. But we read the data on a laptop. Here's one of our downwind runs... https://www.youtube.com/watch?v=5CcgmpBGSCI Thanks again for all your help. I think I'm also going to try an SPI flash IC for this application. Best regards. Rick Cavallaro |
That is an awesome video! Thanks for sharing. SO COOL. Salt flats in Utah? Looks like fun. The application makes a lot more sense to me now (record, read, report, need to be all sealed up). I'll try to write a tighter read example that drops less characters. I think it's do-able, I just never had my head wrapped around an application. |
I just tried reading it byte-by-byte. I turned echo off and I actually read 6 bytes for each request (I guess the response includes a prompt, , etc.). This is slow, but works well with no more drops. This would seem to show you were definitely correct about the busy processor. I'm embarrassed that that hadn't occurred to me. Here's my current code for reading the file byte-by-byte: void readFile(char *fileName)
Sorry to have put you to so much trouble for my silly problem. But I really appreciate it. I think the SPI flash IC is probably the better approach for this application since there's no need for physically removing the memory/card. I think I'll give that a try. Thanks again. Rick Cavallaro
|
Hi Rick - no problem at all. It gives me a chance to write some code :) I committed a new large file example that successfully reads a large file from OpenLog at 9600, connected to the hardware RX/TX on the Arduino. It then spits those characters back out over software serial at 14400 or higher. If you can setup your Bluetooth connection to work at a higher baud rate (say 57600) then this example should show you the basics. Going to close the issue. Please let me know if you run into more problems - and send us more project updates! |
Thanks very much. I'll check it out. If it's not already - you should put a link to it on the OpenLog page on your website. Rick C.
|
I'm using the sample code provided here...
https://github.com/sparkfun/OpenLog/blob/master/firmware/examples/OpenLog_ReadExample/OpenLog_ReadExample.ino
It's supposed to:
It can write the file fine, but often fails to open the file to read - or succeeds, but seems to get a fair number of errors when it goes to read it.
On the other hand if I write a new file, and then open one of the older files to read, it seems to handle both fine - and without errors.
Any tips would be greatly appreciated. Thanks.
The text was updated successfully, but these errors were encountered: