PING)), LCD, and Servo Combination Problems
Bill Chennault
Posts: 1,198
All--
Environment: SX28 at 4MHz on a PDB with a USB SX-Key·and the 7.5v Parallax wall transformer.
PING)) works fine for me and is amazingly accurate.
My Parallax parallel 2x16 LCD works fine with the demo programs, including the modifications I make to them.
The servo is easy to use, although I probably do not understand it thoroughly.
I can make PING)) work with the LCD.
I can make PING)) work with the servo.
I CANNOT make PING)) work with the servo AND the LCD. When the servo works correctly, the LCD displays garbage (seen in the first·clip). When the LCD works correctly, the servo is highly stupid (seen in the second clip). By the way, you probably cannot read the LCD display in the second clip, but it is displaying·the correct PING)) distance.
My impression is that there are timing issues that prevent the LCD working with the servo code. I have attached the code plus two very short video clips of how it executes: Servo Working and LCD Working. The only difference between the two video clips is shutting down the IDE, turning off the PDB, and removing and replacing the USB connection.
Here is the meat of the code. (The entire code is attached.)
Start:
· PLP_A = %0000·····' pull-ups on unused pins
· PLP_B = %1111_1110
· PLP_C = %0000_0011
Lcd_Setup:
· DELAY_MS 500·····' let LCD self-init
· LCD_INIT· ·····' initialize (multi-line)
Main:
·· for idx = 0 to pulses
··· tmpB5 = idx/30
··· tmpB6 = __REMAINDER
··· if tmpB6 = 0 then····' Ping every 0, 30, 60, and 90 pulses
····· ' Ping . . .
····· distance = GET_DISTANCE
····· DELAY_MS 100
····· ' Send Distance to LCD . . .
····· LCD_CMD LcdCls
····· DELAY_MS 25····' for effect
····· LCD_STR "Distance: "
····· LCD_DEC distance, 5
····· DELAY_MS 25
··· endif
··· pulsout servo, 1000
··· DELAY_MS 20
· next
· for idx = 0 to pulses
··· tmpB5 = idx/30
··· tmpB6 = __REMAINDER
··· if tmpB6 = 0 then····' Ping every 0, 30, 60, and 90 pulses
····· ' Ping . . .
····· distance = GET_DISTANCE
····· DELAY_MS 100
····· ' Send Distance to LCD . . .
····· LCD_CMD LcdCls
····· DELAY_MS 25····' for effect
····· LCD_STR "Distance: "
····· LCD_DEC distance, 5
····· DELAY_MS 25
··· endif
··· pulsout servo, 500
··· DELAY_MS 20
· next
· GOTO Main
I sure would appreciate any comments you might have.
Thanks!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Environment: SX28 at 4MHz on a PDB with a USB SX-Key·and the 7.5v Parallax wall transformer.
PING)) works fine for me and is amazingly accurate.
My Parallax parallel 2x16 LCD works fine with the demo programs, including the modifications I make to them.
The servo is easy to use, although I probably do not understand it thoroughly.
I can make PING)) work with the LCD.
I can make PING)) work with the servo.
I CANNOT make PING)) work with the servo AND the LCD. When the servo works correctly, the LCD displays garbage (seen in the first·clip). When the LCD works correctly, the servo is highly stupid (seen in the second clip). By the way, you probably cannot read the LCD display in the second clip, but it is displaying·the correct PING)) distance.
My impression is that there are timing issues that prevent the LCD working with the servo code. I have attached the code plus two very short video clips of how it executes: Servo Working and LCD Working. The only difference between the two video clips is shutting down the IDE, turning off the PDB, and removing and replacing the USB connection.
Here is the meat of the code. (The entire code is attached.)
Start:
· PLP_A = %0000·····' pull-ups on unused pins
· PLP_B = %1111_1110
· PLP_C = %0000_0011
Lcd_Setup:
· DELAY_MS 500·····' let LCD self-init
· LCD_INIT· ·····' initialize (multi-line)
Main:
·· for idx = 0 to pulses
··· tmpB5 = idx/30
··· tmpB6 = __REMAINDER
··· if tmpB6 = 0 then····' Ping every 0, 30, 60, and 90 pulses
····· ' Ping . . .
····· distance = GET_DISTANCE
····· DELAY_MS 100
····· ' Send Distance to LCD . . .
····· LCD_CMD LcdCls
····· DELAY_MS 25····' for effect
····· LCD_STR "Distance: "
····· LCD_DEC distance, 5
····· DELAY_MS 25
··· endif
··· pulsout servo, 1000
··· DELAY_MS 20
· next
· for idx = 0 to pulses
··· tmpB5 = idx/30
··· tmpB6 = __REMAINDER
··· if tmpB6 = 0 then····' Ping every 0, 30, 60, and 90 pulses
····· ' Ping . . .
····· distance = GET_DISTANCE
····· DELAY_MS 100
····· ' Send Distance to LCD . . .
····· LCD_CMD LcdCls
····· DELAY_MS 25····' for effect
····· LCD_STR "Distance: "
····· LCD_DEC distance, 5
····· DELAY_MS 25
··· endif
··· pulsout servo, 500
··· DELAY_MS 20
· next
· GOTO Main
I sure would appreciate any comments you might have.
Thanks!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Comments
So, instead of PAUSE 1000 you would use SERVO_DELAY 1000. Of course, pos needs to be set first.
Thanks for the hint! I will implement it tomorrow and see what happens.
It must be possible to do this with an SX, because I HAVE the BS2 code that will do it on the BOE-Bot. It has become a learning issue with me, even though I will eventually just use three PING)) sensors on my machine.
Thanks, again.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Forgive me. I don't think I wrote clearly.
What I will PROBABLY do is simply mount three PING)) sensors solidly to the front of the machine at angles to one another such that I can cover the forward, say, 90*, or so. I'll activate one on the side, read it, then the front one, read it, and then the one on the other side and read it. I may not sweep back the other direction. Instead I'm thinking I could just start over as outlined above.
Another thing that seems neat to me is the idea of making each PING)) a smart sensor, somewhat along the lines I followed with the BS2p40 and the four OEM-BS2 Stamps that formed the brains of Ugly Buster and then RC Buster. I think a "fast" Stamp dedicated to each PING)) would do this nicely.
However, the programming issue involving the servo and PING)) and the LCD (I don't really need the LCD, but I thought it would be neat to·look at while the robot pings around) intrigues me, especially since I don't seem to be able to do it! [noparse]:)[/noparse]
So, I am going to follow your advice tomorrow, first!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.