Best way to show value of a variable in the IDE

sorry if this sounds a bit daft, but I’m having problems reading the value of “sense”.
I’ve only started using Mbasic last week having been using Pbasic previously. Seems like the debug command is not so straight forward as Pbasic.
Basically I want to be able to see the value of “sense” in the IDE. From browsing the forums I have noticed discussions on displaying items in the terminal using serout, is this another option for me? Thanks.

LineSnsrPwr CON 10 ’ line sensor power
LineSnsrIn CON 9 ’ line sensor input
’ ----- Variables ]------------------------------------------------------------
Sense VAR Word ’ sensor raw reading
’ ----- Main Code ]------------------------------------------------------------
Read_Sensor:
HIGH LineSnsrPwr ’ activate sensor
HIGH LineSnsrIn ’ discharge QTI cap
PAUSE 1
RCTIME LineSnsrIn, 1, Sense ’ read sensor value
LOW LineSnsrPwr ’ deactivate sensor
Display:
debug [dec sense, 13]
PAUSE 100
GOTO Read_Sensor[/code]

I think the problem is that you put the debug command in the sub “Display”. Try this:

[code]
LineSnsrPwr CON 10 ’ line sensor power
LineSnsrIn CON 9 ’ line sensor input
’ ----- Variables ]------------------------------------------------------------
Sense VAR Word ’ sensor raw reading
’ ----- Main Code ]------------------------------------------------------------
Read_Sensor:

HIGH LineSnsrPwr ’ activate sensor

HIGH LineSnsrIn ’ discharge QTI cap

PAUSE 1

RCTIME LineSnsrIn, 1, Sense ’ read sensor value

LOW LineSnsrPwr ’ deactivate sensor

goto Display

Display:

debug [dec sense, 13]

PAUSE 100
GOTO Read_Sensor[/code]

Also try to separate the lines in your code a little better. It make’s the code alot easier to read. :slight_smile:

BTW everyone says to use serout because it’s supposed to be quicker. I dunno how true that is, but I do kind of notice a slow down in code when using debug.

Thanks. That seems to work better , the debug window is displaying 2 repeatedly under each other, not the result I was hoping for! should display a number somewhere between 5000 and 50000 depending on what its sensing. when I put an object in its view it makes no difference to whats displayed in the debug terminal.
If I wanted to display “sense” using serout how would the code look? sorry, not being lazy just looking to be pointed in the right direction, thanks. Do you think it would help using serout?

It really doesn’t matter if you use debug or serout, you will get the same result.

Anyway, the code is like this:

serout s_out, i38400, [dec sense]

Of course you will have to click the “Terminal1” in the IDE and set the Baudrate to 38.4k, and you should be all set.

What exactly are you trying to read?

Trying to read a reflective object sensor for a line follower. At the minute I’m sub system testing. I have a lynx track and L5 arm on it. Was using the bs2 up until now but needed the atom for the a/d channels. So I’m in the process of transfering the code for the sensors and servos to Mbasic. I know the sensors are working because I can check them with the bs2. However I cant write the code for line following in Mbasic because I cant read the object sensor with the IDE.
I used serout there and like you said it had the same result. Just displays a 2 repeatedly.

You’re using the A/D pins? I don’t know what kind of sensor your using, but you should be using the ADIN command for the A/D pins.

Try this code here. Note I changed the pin number to AX0 (the A/D pin). Not all pins are A/D. you can only use the pins AX0-AX3.

LineSnsrPwr CON 10 ' line sensor power
LineSnsrIn CON 9 ' line sensor input
' ----- Variables ]------------------------------------------------------------
Sense VAR Word ' sensor raw reading
' ----- Main Code ]------------------------------------------------------------
Read_Sensor:

HIGH LineSnsrPwr ' activate sensor

HIGH LineSnsrIn ' discharge QTI cap

PAUSE 1

ADIN ax0, 1,ad_ron, sense ' read sensor value (changed to pin AX0)

LOW LineSnsrPwr ' deactivate sensor

goto Display

Display:

serout s_out, i38400, [dec sense] 

PAUSE 100

GOTO Read_Sensor


I’m not using the a/d pins. Just said it was the main reason I changed to the atom!

Is your sensor returning an analog value? if it is you will need to use adin.

tried that, didn’t think it would work and unfortunately it didn’t. RCTIME command returns a value in us, it’s just timing when the logic state of the circuit changes I dont think it requires the adin command. I could be wrong but the BS2 doesn’t have an a/d channel and the sensor works fine in the RCTIME set up in Pbasic. I am appreciating your help though, thanks.

Perhaps you could submit a schematic so we could help you do this in the best way available. If the sensor can provide an analog output it would be best to connect it to an analog input.

unfortunately I cant add a schematic, It is basically a parralax QTI sensor except I’ve matched the components and soldered it onto my own board. But it is the exact same in every way. They use it in there sumo bot to detect the outer rim of the ring. There is a circuit diagram on there website under the line follower product. I have tried to cut and paste the diagram in but cant succeed.
There is no doubt that the sensor works. I have similar problems trying to display the readings of a simple IR detector circuit in Mbasic. In that case I am only trying to display a logic 1 or 0 in the terminal. Again sensor works and can be read in the debug window in Pbasic.
I finding it hard to understand that if rctime is the best way to read this sensor in its circuit using Pbasic, why it wouldn’ t make sense that it is the best way to read it using Mbasic if RCtime is the same command in both languages.

Command is the same, but the hardware isn’t.

Edit: parallax.com/Portals/0/Downl … orrev1.pdf

It looks to me like it outputs an analog voltage. I will create a program to test it on Basic Atom. just give me a sec.

Ok, use this program to test the sensor.

sense var word

Main
     
       adin ax0, 1, ad_ron, sense
       pause 100
       serout s_out, i38400, [dec sense]
goto main

It’s pretty simple. Also make sure you have it connected properly. You aren’t supposed to connect it the same way as you did with the basic stamp. Connect it the same way you would connect a servo except put the 5v jumper on AX0.

Hope it works!

I’m pretty sure the circuit is not designed to provide an analog output.

Can you post the code you are trying on the Atom? Also is it an Atom or a Pro?

Both controllers should have no trouble with measuring the RC circuit.

I copied the BS2 code as a reference from the PDF file:

' ----- Title ]---------------------------------------------------------------- ' Mini-Sumo 3.1 : Line Sensor Test ' {$STAMP BS2} ' ----- I/O Definitions ]------------------------------------------------------ LineSnsrPwr CON 10 ' line sensor power LineSnsrIn CON 9 ' line sensor input ' ----- Constants ]------------------------------------------------------------ ClrEOL CON 11 ' clear to end of line (DEBUG) ' ----- Variables ]------------------------------------------------------------ Sense VAR Word ' sensor raw reading ' ----- Main Code ]------------------------------------------------------------ Read_Sensor: HIGH LineSnsrPwr ' activate sensor HIGH LineSnsrIn ' discharge QTI cap PAUSE 1 RCTIME LineSnsrIn, 1, Sense ' read sensor value LOW LineSnsrPwr ' deactivate sensor Display: DEBUG Home DEBUG "Sensor ", CR DEBUG "-----", CR DEBUG DEC Sense, ClrEOL PAUSE 100 GOTO Read_Sensor

That’s the code he was using already.

RobotDude, have you looked at the schematic? it looks like there’s no digital circuits in there…

http://www.majhost.com/gallery/DarthToa/Robots/circuit.png

Yes I looked at the circuit. :unamused:

It is designed to allow you to charge a cap and measure how long it takes. The amount of time will vary depending on how much IR light is “sees”…

ground out the black wire. Apply power to the white wire. Take the red wire to ground to discharge the cap. Then use the RC command on the pin the red wire is on.

Ok…so maybe i was wrong. :stuck_out_tongue:

I looked up RCTime in the manual. It states that you’d actually need to divide the result by 1.83. Just to let you know.

BTW I think we’ve gone off topic here.

It’s still content based on the original topic. Just need to see his code.

I wonder are the semantics of rctime the same between the basic stamp and Atom Pro. In particular I see that on the Stamp:
State is a variable/constant/expression (0 - 1) that specifies the desired state to measure. Once Pin is not in State, the command ends and stores the result in Variable.

On the Pro:
state is a variable or constant (1 or 0) that specifies the state
which will end the timing period

Maybe I am just reading it wrong, but they seam opposit to me and so you might try changing your code from a 1 to a 0?

Kurt