OneWire connectivity gots corrupted by Servo[SOLVED]

Servo and Dallas OneWire sensor do not work same time, but Servo movements corrupt reading temperature

See that peeks? It is servo moving. Project can’t be modified to have 2 power sources. Power line for servo already has LC power filter.

Same hardware setup(Same servo, same input voltage source) works good on Arduino Nano even without LC filter.

Need some ideas. Can it be corrected with software?

My only idea is to add delay after moving servo

First I would verify that the correct value 4.7K resistor to +3.3V is present on your onewire DQ line.

In software, when you read the scratchpad register on the ds18b20, there is a CRC byte which can be used to check the integrity of the data (temperature) read out of the scratchpad. If the CRC check does not pass then the software can re-read the scratchpad until the onewire bus read operation is error free.


Before I try and replicate this issue or look at the firmware, may I suggest adding a bigger capacitor (>470uF) on the power line? Another thing to try is to power the sensor from the 3V3* pin on the :spark: Core.

To rule out the possibility that it could be a software glitch and not a noise-on-the-powerline, could you temporarily power the servo with an external supply?

Good point about trying external power. I’ll try. Currently it is 3000uF/20V capacitor on power line already :smiley:

Tried external power for Servo - no issues. So it is power line. Too bad I need to deal with it.
Will Dallas sensor work from 3V3* line?

No, CRC is turned on already

Another point to note: How are you powering your Core? Is it through the USB or via the VIN? If its via the USB, and you are powering the Servo via VIN, then the current will be limited to 500mA.

It should, since its rated for 3V - 5V DC.

It is powered from 18650 USB charger. power line goes to spark to VIN and to simple LC filter which then goes to servo. Dallas sensor currently shares power line with servo. I’ll try putting it on different line.

mattande’s solution sounds good to me. Also, with a simple change can you make your code or the OneWire library ignore the temp sensor input while the servo is moving? Servos are very power hungry, so you can add 10,000uF and the voltage could still drop if you have a big enough load on your servo. If your servo is dragging the supply voltage down it’s probably best not to ignore this with band-aid fixes to your code… and provide a better power supply to your servo.

This argument that it works on Arduino but not on the Core always gets me… it really should work on both, but they are so different in many small ways that it could be a very subtle thing that makes it not work on the Core. Just for reference, is your Arduino Nano 3.3V or 5.0V?

This is most likely will be the solution as I dont need to move it often. Also 0.33uf ceramic capacitor on servo signal line makes noise a bit lower. I’ll also try to look for servo alternative that would propably be slower, but would consume less currency.

Also, is there a way to limit current of some hardware? So for example if it exceeds, it gots either powered off for little time, either current is limited.

I’ve used the 2 transistor (NPN) current limiter in a few things with success. It’s nice for circuits that don’t have a lot of head room voltage wise:

You can use something like a LM317 current limiting IC to do the same thing, and program it with one resistor, however it needs a lot of headroom because it needs to drop at least 1.25V across the current sensing resistor before it starts to regulate. Not to mention the IC itself drops anywhere from 1.5 to 3V depending on which mfg you use. So it’s really only good for higher voltage supplies and post voltage regulation (if you need this)

PTC fuses are also a decent solution, but have a slower response… and you have to carefully look at the trip current vs holding current vs. operating temperature:

You can’t get avoid from comparing to Arduino :smiley: SparkCores are initially clearly described as “Arduino + Wi-Fi” on kickstarter campaign page. So one could imagine SparkCore should be mostly a drop-in replacement.

I understand though that it is actually a completelly different product in hardware and software aspects.

Thanks for information. So I think most reasonable would be to find lower-current servo and upgrade power supply by 0.5-1.0A

I’m not familiar with the “stock” onewire library and code snippet posted here but just because the define is set does not mean the CRC check is actually being performed when reading the ds18b20 scratchpad. The define may only be there to include the crc code in the library, or use the crc code as part of onewire search. Its likely still up to you to use the crc code to check the ds18b20 scratchpad and take the correct action if the bus data was corrupted.

Checking the scratchpad CRC is the correct way to detect if the bus data was corrupted or not. Though as others have suggested here it may also be a good idea to time schedule when you access the bus to avoid known interference.

If the CRC check is being performed and temperature value is still incorrect it may be that there is such a voltage excursion on your ds18b20’s VCC pin that the sensor value is being reset. In that case I would consider adding an RC filter on the ds18b20’s VCC.

Agree here. There is probably a difference in timing inherent in the Arduino version that prevents the servo from moving at the same time as sampling the onewire bus.

In case anyone is interested. I’ve experimented with limiting servo current like one would do with LED - with resistors.
10Ohm one was to much for servo, so I’ve put 2.5Ohm resistor on servo power line. This totally solves dallas sensor issue and servo is still working.

Totally stable temperature here:

Also running project from more powerful source (+1A) was not helping at all. Servo produces too much power noise.