Odd sensor malfunction

I’ve been having some odd stuff happening to my Ping sensor lately. My ping started suddenly going to the “toolong” error piece of my code in my rover arm code. So I tested the sensor out to see if it was working properly with this exact code.

distance var word
mm_distance var word
main

low p11
pulsout p11, 5
input p11
pulsin p11, 0, toolong, 40000, distance
distance = distance/148
mm_distance =  (distance*254)/10
mm_distance = mm_distance + 38
pause 60

serout s_out, i9600, "Distance: ", sdec mm_distance, 13,10]      ;display result in terminal
goto main

toolong:      ; if the program gets here the sensor is not functioning, or wired wrong
sound p9,[5000\5000]
serout s_out, i9600, "Timeout, sensor is not working", 13]
goto main

The sensor worked perfectly just as it should have but contiued to go into an endless loop in the toolong section of the code in my rover arm code. After some troubleshooting I eventually put an hservo command (which there is a lot of in my rover arm code)in my sensor testing code like this.

[code]enablehservo
hservo[p12\0\0]

distance var word
mm_distance var word
main

low p11
pulsout p11, 5
input p11
pulsin p11, 0, toolong, 40000, distance
distance = distance/148
mm_distance = (distance*254)/10
mm_distance = mm_distance + 38
pause 60

serout s_out, i9600, "Distance: ", sdec mm_distance, 13,10] ;display result in terminal
goto main

toolong: ; if the program gets here the sensor is not functioning, or wired wrong
sound p9,[5000\5000]
serout s_out, i9600, “Timeout, sensor is not working”, 13]
goto main
[/code]
The same thing happened as it did in my rover arm code and it went into an endless sensor error loop. So I can pretty much conclude that hservo has somehow started effecting my sensor input and I just can’t figure out why. :frowning:

I’ve tried checking my wire connections and even reinstalling Basic Atom Pro onto my computer but the same issue persists. So I really need a code guru’s help now. Thanks for any help in advance.

Which AtomPro are you using? Which Studio version as well? The more detailes you give about your hardware setup the more likely someone can figure out what the problem is.

Sorry for not including those details in the first place.

IDE is 08.0.1.7
I’m using a BAP 28 on a Bot Board 2 with my testing servo conected to pin 12 and the Ping connected to pin 11. All the jumpers in their correct positions and I’m using a 6 volt battery to power the servos and logic.

One more detail I would like to include is that the sensor worked fine for a while then slowly started to have more and more sensor errors until there was nothing but sensor errors.(when an hservo command is present in the code as far as I can tell)

I just found another important detail.
When the servo is disconnected from the board but the sensor testing code with the hservo command is still present the sensor runs fine. But, as soon as I reconnect the servo the endless sensor error loop begins again.

Are you powering the sensor from 5vdc or VS. It’s an easy mistake to make, but VS will slowly kill your sensor. Another potential problem is if the 6vdc supply is not powerful enough and the microcontroller is resetting…

The jumpers for the regulators are in the right positions.(I’ve made that mistake before and I sure won’t again)
I’m recharging my battery now.

Ummmmmmmmm, :blush: the battery was just to low on charge. Sorry for wasting everyones time. I guess the microcontroller automatically resets when there is to much power strain?

Hey! Glad it wasn’t the other scenario. Glad you got it going! :smiley: