Hello everyone! It's been months since I didn't log in to MRL shoutbox.
 
If I log it's because I need a little help on something that is frustrating me since last night.
I am designing a new hand with much better sensors and sensitivity. AH3503+ micro magnet 2x1mm
So I have made a small code to have it working in MRL instead of only testing via a arduino sketch,
but it turns out the sensor pin which is using A0 doesn't start to poll unless I manually activate it in the oscope.
If anybody has an idea...
 
I have it set like this in my script:
 
readAnalogPin = 0
left.addListener("publishPinArray","python","publishPin")
sleep(5)
left.enablePin(readAnalogPin,1)
 
Here is the complete py script:
 
#This simple sensor InMoov script is tested on MyRobotLab version 1.0.2693
#The result can be seen in the Oscope and with the finger action.

leftPort = "COM3"
readAnalogPin = 0

i01 = Runtime.createAndStart("i01", "InMoov")
leftHand = Runtime.create("i01.leftHand","InMoovHand")
i01.startLeftHand(leftPort)

left=Runtime.create("i01.left", "Arduino")
left.setBoard("atmega328")
left = Runtime.start("i01.left", "Arduino")
left.connect("COM3")

 
def publishPin(pins):
    for pin in range(0, len(pins)):
        print pins[pin].address, pins[pin].value
        if pins[pin].value<=538:
          print "No pressure"
        if pins[pin].value>=541:
          print "Hight pressure"
          FingerGoesBack()  
 
left.addListener("publishPinArray","python","publishPin")
sleep(5)
left.enablePin(readAnalogPin,1) # THE NUMBER 1 IS HOW MANY POLLS / SECONDS

i01.leftHand.setAutoDisable(True)

def moveFingerSlowly():
    i01.leftHand.index.enable()
    i01.leftHand.index.setVelocity(25)
    sleep(2)
    i01.leftHand.index.moveTo(180)

def FingerGoesBack():
    i01.leftHand.index.enable()
    i01.leftHand.index.setVelocity(-1)
    i01.leftHand.index.moveTo(0)

 
UPDATE
 
Solved the polling issue by replacing with:
 
#readAnalogPin = 0
left.addListener("publishPinArray","python","publishPin")
sleep(5)
left.enablePin(54,1)
 
In addition (thanks to Ray), I added:
 
def publishPin(pins):
    for pin in range(0, len(pins)):
        print pins[pin].address, pins[pin].value
        if pins[pin].value<=538:
          print "No pressure"
        if pins[pin].value>=538 and pins[pin].value<=540:
          print "Low pressure"
          FingerGoesBack()
        if pins[pin].value>=540 and pins[pin].value<=543:
          print "Soft pressure"
          FingerGoesBack()
        if pins[pin].value>=543:
          print "High pressure"
          FingerGoesBack()
 
 
For the Arduino sketch I was using this code:
 
int mid;
int diff = 2;                    
int raw;
int calruns = 10;
unsigned long calibration = 0;

void setup()
{
    Serial.begin(115200);
    findmid();
}

void Measurement()
{
    raw = analogRead(0);   // Range : 0..1024

    if(raw < mid-diff || raw > mid+diff)
    {
        Serial.print("Output: ");
        Serial.println(raw-mid);        
    }

}

void findmid()
{
    delay(100);
    Serial.println("Setting up... Please wait");
    for(int i = 0; i < calruns; i++)
    {
        raw = analogRead(0);
        calibration = calibration + raw;
        delay(200);
    }
        mid = calibration / calruns;
    Serial.print("Midpoint found at ");
    Serial.println(mid);
    Serial.println("Ready:");
}

void loop()
{
    delay(25);
    Measurement();
}


 
And did:
 
#include <Servo.h>
 

MdG_NL

5 years 12 months ago

Cool to see some progress Gaël, with this Finger Hall-sensor setup!

It looks there isn't a big resolution in your test, 538 true 543.
Normalwise without a magnet by the sensor, it must be around 512.
Is there some space left, to closer the sensor more to the magnet? I hope it gives a bigger resolution.

Other option is to try a other sensor, like this one: https://sensing.honeywell.com/SS495B-linear-and-angle-sensor-ics

Regards,
Marten

Hello Marten

Currently I do not have a 10k resistor at hand, so it's direct connection.

Not very good, but I didn't have the time to go shopping for a resistor.

I'm guessing this is causing the poor resolution.

Hi Gaël,

For these type of hall-sensors you don't need a resistor!
With a digital pin use, there you will need one Pull-Up/Down resistor, or use the Pull-Up resistor from the Arduino board.

For a digital use, it's also better to not use Linear based Hall-sensors, more a type with a smith-trigger inside.
With this it's just On or Off and not in between.
Here some info with different types: http://bildr.org/2011/04/various-hall-effect-sensors/

Regards,
Marten

Just a bit more info about the range.

Currently it varies from 538-->595.

If I would put the magnet urther away, I would increase the range. But I think it is fine enough. It is very sensitive, and you can also apply really a lot of pressure.

Hi Gaël,

This 1881 is a typical Digital Hall-Sensor Latch switch !
That's why you see at the output side "digital out".
Inside this Hall-sensor there is a Schmitt trigger.

Copy from the datasheet: https://www.sparkfun.com/datasheets/Components/General/Hall-US1881EUA.pdf


General Description: 

The Melexis US1881 is a Hall-effect latch designed in mixed signal CMOS technology. 
The device integrates a voltage regulator, Hall sensor with dynamic offset cancellation system, Schmitt trigger and an open-drain output driver, all in a single package.

 

The one you are using now, is a linear type and that's a big defference.
It needs no Pull-up resistor.
Here a site in your language: https://wiki.mchobby.be/index.php?title=Senseur-Hall-SS495A

I hope to find my (same) hall-sensors tomorrow, so I can also test the difference.

Regards,
Marten

After a test this day, here the results from the sensor reads SS495A:
The lowest valeu = 105 and the highest = 437 (10bit resolution)
The sensor starts without a magnet by 2,5V, so the magnet is close enough to the sensor and when I slide the servo to his maximum, it just reach the maximum sensor valeu.
The distance between the sensor and magnet is now 5mm and is the exact range for the used magnet (2x1mm)

Here some pictures from the test setup:

The spring pulls the servo to the left...
When the finger get's more grip to something, the servo will slide to the right and makes the distance between the sensor and magnet smaller.

The next step is to install the finger and find the correct spring pressure.

Regards,
Marten