SINTEF-9012 / JArduino

Program your Arduino in Java
https://github.com/SINTEF-9012/JArduino/wiki
176 stars 63 forks source link

analogRead in JArduino reports incorrect range of values #54

Closed lobsteroh closed 8 years ago

lobsteroh commented 8 years ago

same hardware setup (4 channel capacitance sensor OSEPP 4DTOUCH-01. channel 1 into analog pin A0) reports very different values and ranges when running AnalogInOutSerial.java or built-in example AnalogInOutSerial

Arduino example gives background values around 350, increasing to 900 when I touch sensor JArduino example gives background values around 350, increasing to 385 when i touch sensor

i suspect another error related to unsigned byte vs java byte (8-bit signed) issue i had flagged earlier

in java (byte)128 = (numeric) -128 (byte)255 = (numeric)-1 while (byte)0 - (byte)127 give numeric 0-127

brice-morin commented 8 years ago

Yes, it is probably related to signed/unsigned byte. We might use something like Google's Guava, which support UnsignedBytes in Java. I am however uncertain at this point how big of a refactoring that would imply.

lobsteroh commented 8 years ago

blush ... i was tracking down exactly where the byte[2] gets stuffed into the short with the plan of intercepting it with a call to Guava. i was following the flow of bytes with echo to console when ... the thing starts working AS IS, i can only imagine that one of my jumpers had missed making a connection properly. so, all good. it was a false alarm ... blushing again ...

brice-morin commented 8 years ago

Ok, no problem :-)