EnviroDIY / Arduino-SDI-12

An Arduino library for SDI-12 communication with a wide variety of environmental sensors. This library provides a general software solution, without requiring any additional hardware.
https://github.com/EnviroDIY/Arduino-SDI-12/wiki
BSD 3-Clause "New" or "Revised" License
158 stars 100 forks source link

ATmega328p using 8MHz internal oscillator #51

Closed mkals closed 5 years ago

mkals commented 5 years ago

Hello!

I am trying to make a sensor-node based on the ATmega328p running on the internal oscillator. I have burned the relevant bootloader from here, but when I try to run the SDI-12 library, almost all the characters are wrong (and some are dropped). I have tried calibrating the oscillator and playing with the RX_WINDOW_FUDGE with little success. Everything works as expected when I use a 16MHz external oscillator.

The readings are however consistently wrong (for a given message, the same incorrect message is displayed every time), leading me to think that it is possible to make it work, with the right combination of settings. Have you tried using the library with an internal oscillator before, or do you have any advice on the best procedure for debugging this issue?

Thanks for all input!

SRGDamia1 commented 5 years ago

I've never tried the internal oscillator. It must be a bit inaccurate. You can try tweaking the bits per tick settings a bit to compensate.

SRGDamia1 commented 5 years ago

If you have an oscilloscope you could use that to test how inaccurate the internal crystal is so you know how much to adjust the timing by. You might also be able to see how much millis() differs from a stopwatch.

Also, double check that the prescaler settings are right for the internal oscillator. They might not be the same as when using a crystal.

mkals commented 5 years ago

Thanks a lot for the suggestions!

I used a scope when I calibrated the oscillator. When I make the ATmega328p running the internal oscillator generate a SDI-12 message, it looks identical to the signal generated by any other SDI-12 device.

Checking the prescaler is a great idea! I will look into that this afternoon.

mkals commented 5 years ago

From what I can see, the prescaler should not be impacted by the selection of an internal or external clock source. I will re-spin my boards to add an external oscillator, as I cannot afford to spend more time trying to get this to work. Thanks for the suggestions!

SRGDamia1 commented 5 years ago

Sorry!

You may be able to get it to work by going back to version 1.1.0, which was dependent on micros() instead of the timer/prescaler. I don't know how micros() is affected by internal clock accuracy.