That one is wrong. You have to shift the raw value befor masking.
The lowest bit of the returned value will not be at bit0 of adc, so you have to shift to to the right. Reason: The adc starts shifting out values at the 2nd (or third?) clock cycle, and SPI will create 16 clock cycles. So there are like 14 bits in the result buffer, of which only the high order 12 bits are valid. The others have to be discarded and the value has to be properly aligned.
If you use a separate CS pin, you can simply use spi.read_into().
x should be a value between 1 and 3. Best is to determine it experimentally.
The conv variable and write_readinto() is only used to create the CS signal at the MOSI pin. By using an appropriate pattern for conv, like 0x8000, 0xc000, of 0xe000, you can shift the CS signal in clock steps, making the final shift of the result obsolete. So doing that save a pin and saves a few instructions.
Are you trying to connect multiple sensors to the WiPy and communicate with them via Bluetooth? Connecting multiple BLE nodes to the WiPy is possible. You can find our BLE examples here. Hope this helps, let me know if you have any questions!
Well You should start with documentation and step by step work on representing the dashboard and implement the services according to it, I am also trying work something similar,
So I hope this might help you out
I am also planning something similar but I am facing the same problem. Although, for me their is something more to the story. I am not using the conventional AWS servers, I am using the managed AWS cloud servers which is powered by Cloudways. So, does your research woks fine for me or I have to figure out something else to counter the issue.
@robert-hh Thanks for your reply.
I only have two sensors at hand now. No matter which one I use, it's ok. Since the principle is completely different. For the two sensors, do you familiar with them? Can you teach me some direction about how to program if you know. It's hard to find the same topic in the website and I am extremely confused now. Thanks! This is the image of the sensor, which provided by my supervisor.0_1519505277502_hc-sr04-sonar-sensor.jpg
Hey all, thx a lot for helping me this last days with this driver. This is the code i have until now... it's a shame that i didn't make it, but i think that i could have broken the sensor when i plugged CS to 5v instead of 3V3.
I think i will buy another one, that will take some weeks until it gets to Uruguay :P
Anyway, this is the code we've made until now, maybe it's useful for someone else. It's not throwing the ugly i2c bus error anymore, but the device id registry is returning always zero, and that's bad... not sure if the device is broken or what, but comparing this code with the implementation @livius has referenced, and with other implementations i found on google for other languages, it looks like the retrieval of the device id is the first action almost everyone does, so... i dont know.
from machine import I2C
from machine import Pin
from machine import Timer