Topics
- SD Card Reader
- Logging Temp Data
- Collection Rate with Hardware Debounce
SD Card Reader
I setup my SD card reader on the board. I have confidence in this part completely.
Then I wrote a simple program to test opening a file and writing to the card. I looked up the SD library and tried working with the commands rather than to use the file you had given us. I prefer working as c lose to first principles as I can. Helps me to gain a more intuitive understanding of the material.
What I expect to see when I run this program is the phrase "Test Poops 2!" in the serial monitor. Although I was bit unsure about reading from the SD card in this way, I don't know why I got what I did.
For some reason I got a -1 in the serial monitor. I will have to try to rework the read function I believe. Let me check the card without the arduino and see what I get.
Hmm....it was a complete failure, it would appear. I made a little test bit. This is good news because I am getting closer to finding my problem. My pin isn't being initialized.
I couldn't get mine to work. Switching over to the program you made and I had the same problem.
After much frustration, I turns out that using 32fat can mess with this particular library. I got a smaller SD card and used 16 fat. I was able to create the log after this.
Logging Temp Data
For the lab I was supposed to connect my temp sensor and record the data I got. The stipulation was that I needed data collection for a minute without using delays. To do this I used the millis command and a variable to compare the passage of time to.
The compare didn't always work and I'm not exactly sure why. I was thinking there might be something wrong with the place I am setting the currentTime variable at the end.
After all the stuff in the loop I have this. If I follow correctly, as my while loop first encounters millis being a 1000 beyond zero, the loops runs. After which, the current time becomes the millis time and then the function doesn't run until millis is again 1000 beyond the current time. Effectively creating a collection rate of one per second. The entire structure stops when millis reaches a minute. For some reason, I don't get this to work that way. I get some recording but not the full 60 samples I expect.
I continue to have the problem of data collection not doing what I think i should do. I tried to force a limit on the data collection and something is still haywire. There shouldn't be any way for more that 60 data points but I am getting this endless stream. EHHHHH! I WILL HAVE TO TRY SOMETHING NEW. I THINK THIS IS SOMETHING TO WITH THE WHILE WIREAVVAILIBLE PART OF THE PROGRAM.
I got rid of all the complicated things in my loop that might be causing problems and replaced it with a simple serial print. What i got was the same problem as when I had the full problem (twenty or so printings then the end). What was interesting was that the numbers happened much more quickly than then I had the complicated which leads me to believe that the nondelay delay wasn't actually doing anthing. Rather, I was pushing the SD card as fast as it could go.
My debug was not effective. I declared "int I = 0;" outside of the while and then I got this...
I now know that my while loop idea of how to do the delay will work but I still don't get what I want when I have the "complicated stuff". My problem has to be in the "COMPLICATED STUFF"
I added the brackets around the else statement. I ran it and got the right number but tried running it again before documenting it.
The second test gave me this. I am beginning to feel that something in the hardware starts to fail and my current knowledge is not sophisticated enough to solve that type of problem.
I reran the program a few times and got different numbers until I eventually got what I had aim at. Since I had changed no code I believe the evidence points to a hardware fault. I consider this part done.
Collection Rate with Hardware Debounce
I setup a second button in the same way I had done previously.
I setup the button to pins 2 and 3 to be used as interrupts. I also wrote programs that allowed me to control the collection rate. Before I started I made sure the inverter worked. I do indeed get the inverted values I want and I can see that a raising voltage does signify a new button press.
The program I wrote in order to control the collection rate was simple. I added an extra check to the decreasing rate in order to limit the max rate to once ever .5 seconds. I can also see that the functions work by the serialprints I have inside the functions. I had to do some debugging when I first started because I kept getting this problem with the way my attach parts were working. I thought it was the rising part. I found out I could use 0 and 1 to refer to the pins 2 and 3. It turned out the way I was calling my functions in the attach was a problem. I had been keeping the () that we normally use. Removing those cleared it up. There was still a problem with my down function.
I have no idea why my down function doesn't work.
I thought, "Perhaps, the pins are the problem?" Swapping the two pins had no effect on my data. Calling down still does nothing while up works. Both functions have the same structure, an exceedingly simple one. Must be something else.
This is was odd. I couldn't see any problem with the function itself, so I made down a copy of up and then tried running the program. still it didn't work. There is something going on here. I have to find this problem.
Inside the code, I switched the pins to watch for the interrupt and this completely broke it. I'll try to call the pins by their variable names.
It worked! That is strange. If it was the variable name problem then why did my up function work but not my down function. I think I might be that up is higher up in the code and that means it has some strange priority to work when I use 0 and 1 to watch the pins. I'll test quickly and confirm or reject this hypothesis.
Now I am really lost! IT WORKED WHEN IT HADN'T BEEN DOING ANYTHING AT ALL FOR AN HOUR! Why this sudden change I have no idea.





No comments:
Post a Comment