[MRL 1742] Analog Reader - correct method

Hi ! I have some problems to poll analog pins

Before I used :

right.addListener("publishPin", "python", "publishPin")
right.analogReadPollingStart(1)

def publishPin(pin):
  print pin.pin, pin.value

analogReadPollingStart no worky anymore

 

So I try that :

def publishPin(pin):
  print pin.value

right.addListener("publishPin", "python", "publishPin")    
right.attach("publishPin",1)

no worky

then:

def onPin(value):
    print value
right.addListener("onPin", "python", "onPin")    
right.attach("onPin",1)

but no lucky I am :)

calamity's picture

maybe there is a better way,

maybe there is a better way, but this work

arduino = Runtime.createAndStart("arduino","Arduino")
arduino.connect("COM11")
 
def publishPin(pins):
    for pin in range(0, len(pins)):
        print pins[pin].address, pins[pin].value
 
arduino.addListener("publishPinArray","python","publishPin")
 
#arduino.enablePin(pinAddress, rate)
#analog pin range are 14-18 on uno, 54-70 on mega
#rate is the number of polling / sec
arduino.enablePin(15, 1)
 
calamity's picture

add on the

add on

the enablePin(pinAddress, rate) have been implemented recently and is available on the latest build

enablePin(pinAddress) will be available on Kraken (latest stable)

moz4r's picture

Hi !! Thank you for your

Hi !! Thank you for your awnser. It's better but . mmm. :

I use 1744

right.enablePin(54) ok

right.enablePin(54,1) nok ( error no such method ) I think i have not the last one no problem.

But with right.enablePin(54) I have 1 time on 2 a lot of buffer overrun and finaly crash mrl

22:17:28.967 [python_outbox_0] WARN  org.myrobotlab.framework.Inbox - GUIService inbox BUFFER OVERRUN dumping msg size 1025 - getStdOut

this is my script

right=Runtime.create("i01.right", "Arduino")
right.setBoard("atmega2560")
right = Runtime.start("i01.right", "Arduino")
right.connect("COM4")
 
def publishPin(pins):
    for pin in range(0, len(pins)):
        print pins[pin].address, pins[pin].value
 
right.addListener("publishPinArray","python","publishPin")
right.enablePin(54)

calamity's picture

Hi Moz4r I have recheck

Hi Moz4r

I have recheck enablePin(54,1) and it's working for me, not sure why it's not working for you

I also have problem with just enablePin(54) work well a some random time, then the hells of message errors happen. Look like the optimization we have done on MRLComm is so good the the MRL java messaging can't keep up.

That's why I implement last week-end the alternative method with the rate setting.

 

moz4r's picture

ok , it worky but only One

ok , it worky but only One time. If it is normal may I create a timer ?

 

calamity's picture

found the problem, look like

found the problem, look like my last changes to MRLComm did not found their way to github so the version on my arduino was different than the one with MRL

fixed on v1745, upload the MRLComm to have the fix, I did not change MRLComm version number

sorry  about that and thanks for helping to debug

 

moz4r's picture

It works great !!  Is it

It works great !! 

Is it possible to tweak the timer because I use hall effect sensors and data are not accuracy enough ( the signal is not straigh. The sensors send interesting data, only few micro seconds and I need to be lucky to read it every 1 second.

 

calamity's picture

the rate setting is there for

the rate setting is there for that, at 1 it poll 1 time / sec, at 100 it will poll 100 times/sec etc

moz4r's picture

It is PERFECT . I m playing

It is PERFECT . I m playing with it. thank you again

moz4r's picture

He he the apple test

He he the apple test

calamity's picture

Nice moz4r Happy that you get

Nice moz4r

Happy that you get it working

If I understand, the sensor you are testing are detecting if something was put in the hand?

what kind of sensor did you use?

 

moz4r's picture

This is "hall effect"

This is "hall effect" sensors. they are connected on the arduino, no need wires on the fingers. Need to be optimised because of strange signal