sandeepmistry / node-bbc-microbit

Control a BBC micro:bit from Node.js using BLE
MIT License
83 stars 26 forks source link

Analog pins should be 10bits #18

Closed jaafreitas closed 6 years ago

jaafreitas commented 7 years ago

According to the documentation, analog pins should return a number between 0 and 1023 (included).

lib/io-pin-service.js is reading data as unsigned integer 8 bits

Steps to reproduce: a) plug a potentiometer in P0 b) start example/pin-listener.js c) change the potentiometer from min to max. We will have 4 turns of 0 to 255 values.

It seems that the problem starts with the firmware, because we are receiving only 2 bytes.

Any workaround or suggestion would be great.

jaafreitas commented 7 years ago

I read a bit of the node-bbc-microbit-firmware and the problem seems to be in the microbit/microbit-dal/inc/bluetooth/MicroBitIOPinService.h/IOData struct.

struct IOData
{
    uint8_t     pin;
    uint8_t     value;
};

I have no ideia if changing the value to a uint16_t would be enough to solve this problem in the firmware.

jaafreitas commented 7 years ago

According to the official micro:bit documentation, the io pin service should truncate the analog values to 8bits.

I fixed it by dividing the getAnalogValue() by 4 on onDataRead and idleTick

This firmware is based on an old code and things have changed a bit.

It seems that the node-bbc-microbit code is fully compatible with the Microsoft MakeCode. I'm using it for now.

image

jaafreitas commented 7 years ago

Just in case, if someone decided to fix this old firmware revision, the code is available here

smartyw commented 7 years ago

I think this was already fixed in the DAL:

https://github.com/lancaster-university/microbit-dal/issues/289

jaafreitas commented 6 years ago

Yes, it's already fixed in the DAL. Sadly not in the way I would expect it...

sandeepmistry commented 6 years ago

@jaafreitas that documentation (from https://github.com/sandeepmistry/node-bbc-microbit/issues/18#issue-262318174) is not related to the firmware and BLE interface this library expects.

jaafreitas commented 6 years ago

I'm not sure why you closed this. You couldn't reproduce the problem in the description or you don't think it should be fixed?