SRF04 - BasicAtomPro 28 - BotBoard II

Hey all, I have a minor mayday here…

I am using a BAP28 on a BotBoardII with a SRF04 ultrasonic ranger. My IDE is version 8.0.1.8 and the code, pasted below, is from Jim’s code posted as an announcement in this forum.

I have tried 2 SRF04 units and neither seems to be working via the terminal display. The first SRF04 is on my BAP28 robot and the second SRF04 is on an oopic based robot (wired to BAP28 for test) and tested working (several times) within seconds of running this code. The wiring has been verified countless times.

The terminal display shows nothing, just blank? The only way I know it is running is to Animate it and then it highlights the lines running. The code runs great until it hits the pulsin line and breaks to toolong. Even if the code breaks the terminal should show Timeout, sensor is not working as per the code? but it is not…

Since this code is listed as ‘tested and working’ that leaves me… any ideas what I am doing wrong?

Does anyone have a piece of SRF04 code for the BAP28 that is for sure working they want to share?

[code]
wdist var word
low p10 ;pin to initiate the sensor
low P11 ;pin to measure the return pulse

main:
pause 10
pulsout p10, 20
pulsin 11, 0, toolong, 40000, wdist
wdist = wdist / 148 ;convert for inches
serout s_out, i9600, "Distance: ", sdec wdist, 13, 10] ;display result in terminal
goto main

toolong: ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, “Timeout, sensor is not working”, 13]
goto main [/code]

Thanks a bunch,
Ted

It would probably help to have some additional information, like how you have it wired. What voltages do have going out to the IO pins, etc.

I assume you have done a connect to the proper serial port, etc.

Thanks
Kurt

I guess I could of added that ports power shorting block is jumpered to VCC (+5V). I cannot check voltages out to the pins from home… all my goodies are in my teaching lab. I have to assume (yea, I know) that the BAP28 is functioning properly. It does run a couple of servos correctly on another program.

Wiring is per code to the SRF04. Don’t forget, I can unplug a second SRF04 from a working bot (see my avatar) and plug it into the BAP28 and still no go?

Yea, serial is hooked up correctly and I can switch programs etc… with the expected result. I did check the connect/disconnect several times while playing with the code etc… no result.

Thanks
Ted

Have you tried moving the wires to other pins? Instead of using pins 10 and 11, try 5 & 6 and see what happens.

I think I tried just about every pin combo on the IO excluding the AN and the three pins used for my servos…

Thanks
Ted

I don’t have one of these here to try it out, so I will describe some simple debugging approachs to see if we can figure out what is going on here.

My assumption is that you have 4 wires going from the BB2 to the SRF04. That is two signal wires that are connected to P10 and P11, that go to the pulse and echo. Also you have a power wire going to the +5v and a ground wire. Also as you mentioned you have the jumper set for +5v to the appropriate power pins…

Also you have not mentioned your power connections, but I would verify that your source(s) is connected properly.

Next, lets check to see that your program is not rebooting and that you are properly receiving character output. To do this I would add a few lines to the start of the program.

Maybe something like:

[code]

Sound P9,[60\4000,80\4500,100\5000]
serout s_out,i9600, “Program Start”, 13]

main:[/code]
Note, the … is just the old stuff before main: With this, if you keep getting a sound coming out you know your program is resetting. Also if you don’t get the “program start” when you power up your board you know that maybe you just have a problem, with your setup. That is that serial cable is not plugged in, or you have not configured your terminal window to the appropriate comm port and baud rate or you have not clicked on the connect button.

If you do get this serial output and still nothing else, then maybe try adding the line:

input p11

after the low p11. I don’t think it is necessary but it would not hurt.

If still no go, then I would try using the non timeout version of pulsin to see if maybe there is a problem with the timeout version of pulsin. Something like:

pulsin 11, 0, wdist 

If that works than maybe AcidTech(Nathan at BasicMicro) might need to look at this.

That is all I can think of.

Kurt

I wonder…

You said that you only know that it is running as it highlights the source line that is running. Does that imply you are running it under the debugger? If so serout to S_OUT won’t work as the serial port is taken up by the debugger.

First try running the program not under the debugger. Note: I quite often have had problems with any timing related command such as pulsin running under the debugger anyway…

But if you want to run under the debugger, change the lines:
serout s_out, i9600… to the debug command.

Kurt

Kurt,

I have altered my code via your suggestions and it now looks like so:

[code]wdist var word
low p10 ;pin to initiate the sensor
low P11 ;pin to measure the return pulse
input p11

Sound P9,[60\4000,80\4500,100\5000]
serout s_out,i9600, “Program Start”, 13]

main:
pause 10
pulsout p10, 20
pulsin 11, 0, wdist
wdist = wdist / 148 ;convert for inches
serout s_out, i9600, "Distance: ", sdec wdist, 13, 10] ;display result in terminal
goto main

toolong: ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, “Timeout, sensor is not working”, 13]
goto main[/code]

I made the changes one at a time, tested and the results are as follows:
1 - OK, Makes a sound at every reset or connect/disconnect cycle as well as outputs **Program Start **to the terminal display.

2 - OK, I guess lol. No change.

3 - As expected, the program no longer has a call to the toolong routine so it now reports Distance: 0 in the terminal display.

It is interesting that it reports distance as zero as that leads me to believe it is one of two choices… hardware or pulsin.

Yes, the power connections have been checked to the BBII many times and the jumper removed connecting vcc to vs. I am using a two battery config.

I was unable to test the second SRF04 this am as a student is borrowing it for a bit. I will try that later.

Thanks
Ted

I was running it in terminal in the Animate mode so it highlights the lines of code running.

Thanks
Ted

Hi Ted,

Again this sounds like you are using it in debug mode. Did you click on the Program button or the Debug button.

If you haven’t tried it already try clicking the Program button and then click on the terminal 1 button at the bottom of the IDE and do a connect. I don’t believe there is any such animate unless you are running under the debugger.

Kurt

Kurt,

Sorry about that…my bad. Yesterday while trying to get something to work I was chnging my code to run in debugger than change back to run in terminal. Sorry for the confusion.

I am running in terminal with the code shown in our previous.

Thanks
Ted