NXT Sensor problems (Python), PLEASE help :)


#1

I seriously need a bit of help getting my sensors to work.

I am using the latest version of dexters img file.
I have updated and upgraded the software.

Running the lego motor test works fine, the blue led test works fine, but I cannot get ANY of the sensor tests to work. I have tried and tried and tried. Most probably I have looked at it so hard I can’t see the wood for the trees now.

Can anyone spare the time to talk me through it step by step please. I would dearly appreciate any help.

I have tried running this python code too, but again no luck at all:

from BrickPi import *

BrickPiSetup()

BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH
BrickPi.MotorEnable[PORT_A] = 1

BrickPiSetupSensors()

while True:
result = BrickPiUpdateValues()
if not result:
if BrickPi.Sensor[PORT_1]:
BrickPi.MotorSpeed[PORT_A] = 200
else:
BrickPi.MotorSpeed[PORT_A] = 0
time.sleep(0.01)

I have tried deleteing the # in the debug =1 line in BrickPi to get it running in debug mode but that didn’t work.

Please help me if you can, it will be much appreciated


#2

Hey Pi,

You wrote:

Running the lego motor test works fine, the blue led test works fine, but I cannot get ANY of the sensor tests to work. I have tried and tried and tried. Most probably I have looked at it so hard I can’t see the wood for the trees now.

So you weren’t able to get the touch sensor test to work at all? Did any of the sensor examples work?

Also, just to double-double check, your sensors were plugged into the correct ports?


#3

Hi John,

Thnk you very much for your reply.

I did try the touch sensor test but had no luck getting it to work. I set it up in exactly the same way as this picture:
;

(with the sensor plugged into s1 and the motor plugged into MA, top right corner.) I also tried modifying the code to look at different sensor and motor ports, but still no response

I first ran the test with the micro usb suppling power to the pi, and a 6x AA battery pack plugged into the BrickPi, then i tried unplugging the micro usb and running just on batteries. Both times the touch sensor failed to start the motor. (I have verified that both the NXT sensor and motors and cables work with my nxt brick)

I did get some kind of response from the nxt light sensor when I ran the red led test, the red light on the sensor briefly flashed 3 times. But I couldnt get the sensor to respond to black/white or colors. The same was true for the ultrasonic sensor.

I tried running the test from an ide window, and also from a terminal window, apart from the tests soley for the motors, all other tests requiring sensor input failed to complete.


#4

Going back to your original problem, it sounds like you haven’t been able to get the sensor tests to work?

Can we simplify this a bit. When you run the original touch sensor test, what results do you get? It would be really helpful if you could post a picture of the screen as you run the test.

https://github.com/DexterInd/BrickPi_Python/blob/master/Sensor_Examples/LEGO-Touch_Sensor_Test.py

A few quick pointers:

  • The example program has the touch sensor on Port 4. So please put the touch sensor on Port 4.
  • Be sure to use “sudo” when running the python program.

How does that go?


#5

Hi there, I am including my screenshot of the result of running the code as listed in the link above.

It seems the program just hangs around waiting for a signal that never comes.

sorry for the delay in responding, and thank you for your continued help :slight_smile:

test


#6

Just wanted to double-check: you have the same code in the file touchTest.py as LEGO-Touch_Sensor_Test.py and the sensor is on Port 4?


#7

Yes to both questions John :slight_smile:


#8

Well I finally got the sensors working. Strange story though.

I have two raspberry pis at home. Using these pies I couldn’t get the brick pi working which made me think there maybe was something wrong with the brick.

Just before I gave up and sent it back for a checkup I asked my friend to take a look and see if he could have any luck with it.

He plugged in his raspberry pi, using the sd card from my pi and the sensors worked first time.

It’s a strange one, all 3 pis are the B model, were bought at the same time from the same shop. 1 works with the brick, two don’t.

Fortunately now my students and I can get on with having fun with the brickpi. Thanks to John for stepping up to give a hand, and thanks to all you guys at Dexter for making a great product at a great price.


#9

I’m glad to hear the problem is solved. Thanks for your compliments, but I’m afraid we left you hanging. I would love to know more if there are any diferences in the two Pi; this must have been a maddening problem.

Glad it’s resolved though!


#10

I am really not sure. I do know that at one point the brick was inserted incorrectly to the pi( the first two sets of pins on the right side (with the card orientated with the pin connector towards me) were left exposed so it may be that something happened to the pis as a result of that. I reinsterted the brick correctly once i saw the problem.

The only other thing I changed was instead of running the pi from my laptop usb to the micro usb connection I used a powersupply directly into the pi. I did notice that the sensors and motors work with this configuration (albeit that the motors turn slowly) with a 6 pack battery pack also plugged in everything is great with the touch sensor motor set up.

Now fiddling around learning how to get the lego color sensor to work properly. all good though as its helping me brush up on my python skills :slight_smile:


#11

Just want to finish off this thread by saying I now have a fully functional brick pi, using nxt motors and sensors.

Most of my problems were self inflicted, for example fiddling around trying to get a light sensor to work using color sensor code (felt pretty silly when I found that one out) Got the sound sensor working using the general analogue test set up. Ultrasonics working great, touch sensors working.

All in all I am a very happy brick pi owner, and the problems I had, have led me to a far greater understanding of how everything works than would have been the case had it fired up straight out of the box.

Couple of suggestions I would make, get an external power supply for the pi rather than using usb to micro usb, usean 8AA battery pack for powering the brickpi, and only unplug the mains cable when you need to.

Learning how to share internet connections from the pi to my laptop was tricky, as was getting the remote desktop working.

But as I watch my brick pi line follower happily sensing its way round my track all that melts away into a happy glow :slight_smile:

Love the pi, love the brick!