-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOpin service documentation #13
Comments
I haven't had the chance to set this up, so haven't documented it. I was working in the dark a little, so any help from the community here would be awesome. I'm happy to write up some basic docs if someone has this working. @benmoran Anything you could share? |
Hi! @LoFiRobot
Before the little endian patch, these functions didn't work - you'd get a list of 24 garbage ints instead. (You don't need to do any bit twiddling from javascript, unlike the raw C++ api which expects a single 24bit unsigned int - @thegecko has thoughtfully done that for us) |
I think I am using latest version of the library - I cloned the repo few days ago. When it comes to pin readings.
let io_conf = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; nothing changes - using getIoConfiguration afterwards still returns array of zeroes.
So i tried it that way: [65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0] However when I reset the microbit, reconnect to your library and try to pass the same array to setIoConfiguration - no effect, getIoConfiguration returns zeroes. When I am setting P0 to analog input IO and AD in NRF app ( passing 0x01000000 to both characteristics) then reconnecting to your library and using services.ioPinService.readPinData() I recieve proper readings from the pin - {pin: 0, value: 83} So part I am missing is how to use setIoConfiguration and setAdConfiguration methods properly. |
Update I still have not managed to figure out how to use setIoConfiguration and seAdConfiguration methods. But I managed to set pins configuration by writing to characteristics directly:
Important part is the cmd variable - each pin has its address To set P0 to analog read - pass 0x01 to both IO and AD characteristics. To set P0 and P1 to analog read - sum the bytes - pass 0x03 to IO and AD To read the values simply call: Performance suggestion: It would be nice to have an eqivalent of |
Nice, feel free to create a separate issue in case I forget ;) |
Do you have any example on reading analog from pin 1? I'm getting crash on browser and also on microbit....I thing it has to do with giving the period of 50ms before read. Any javascript examples code would be nice. |
Hey dakandaka, I am using timer to ping the service for data (the interval is 100ms, no crashes): componentDidMount() { async timer() {
} |
thank you for quick response :) I see componentDidMount() you are doing it in react? and state...I think it is react. |
Yes it is React. The app live is here: BLE component import React, {Component} from 'react'; let check_connection_interval = null; let x = 0; let MBdevice = null; class BLE_connect extends Component { constructor(props) { } componentDidMount() { async timer() {
}
} async connect_ble() { const onDisconnected = event => { } const eventHandler = event => {
} const device = await window.microbit.requestMicrobit(window.navigator.bluetooth);
} send_ble(key,value) { let _key = key; if (key === 208) { let pwm = { if (key === 211) { } render () {
<button id="connect_button" className= { onClick={() => this.connect_ble()}> {//
} export default BLE_connect |
Hey Rob,
Thanks for your great library! It really simplifies talking to micro:bit over web-bluetooth.
I cannot find any documentation about accessing IOpin service.
After diggin into console I managed to work out PWM control to operate a servo motor.
....
Still I am confused how to take analog readings from IO pins. Setting AD and IO configuration with bitmasks is a riddle to me. Could you please provide any code sample how to set:
setIoConfiguration and getAdConfiguration to configure P0 , P1, and P2 for analog readings??
Thank you in advance.
Maciej
The text was updated successfully, but these errors were encountered: