Wiz-IO / platformio-quectel-examples

Examples for PlatformIO Quectel
29 stars 21 forks source link

DS1820 / DHT Example - pin mapping #11

Closed artursmet closed 3 years ago

artursmet commented 3 years ago

Hi,

Are the pin mappings from variant_pins.c up to date?

I have the Olimex NB-IoT devkit Rev B and I have connected the DHT22 sensor's data pin to GPIO 1 (according to this schema - https://raw.githubusercontent.com/OLIMEX/NB-IoT/master/HARDWARE/NB-IoT-DevKit-pinout.png)

I've run the example code https://github.com/Wiz-IO/platformio-quectel-examples/blob/master/BC66_SDK/Arduino/BC66_A11_DS1820_DHT_GPIO/src/main.cpp and set it to the DHT mode.

Based on the variants_pins.c I've set:

#define DHT_A_PIN 9 
#define DHT_M_PIN 28

However, the module is failing to get the data from sensor:

DHT: Failed to get reading from PIN, dying
Temperature = 0.000000, Humidity = 0.000000

What could I do to get it working as expected? I have also tried running the example with DS1820 sensor and the resistor, but also it looks like the module can't find the sensor attached to the GPIO port, that's why I suspect some problem in the sample code.

Btw. Why do we need to have two port numbers (A_PIN and M_PIN)?

My wiring is pretty much the same as this: image

But instead of arduino I have the NB-IoT devkit of course.

When I switch it to the DS1820 sensor (with resistor) I receive:

Init Error( 1 )
ID 00 00 00 00 00 00 00 00 
Init Error( 3 )
Wiz-IO commented 3 years ago

Hi the module use SoC and Mediatek SDK and pin enumeration ( hidden for the user ) https://github.com/Wiz-IO/framework-quectel/blob/master/arduino/variants/bc66-te-b/variant_pins.c#L26 column 2

OpenCPU have Quectel enumeration PINNAME_xxxxxx https://github.com/Wiz-IO/framework-quectel/blob/master/opencpu/bc66/SDK15/include/ql_gpio.h#L44

Arduino port use Quectel OpenCPU API as default user access and applications
and some "hacks" for direct access to original Mediatek SDK, opportunities and SoC registers

so...

define DHT_A_PIN 9 is used for default Arduino pin configurations as pinMode(DALLAS_A_PIN, INPUT);

define DHT_M_PIN 28 is user direct read/write to SoC GPIO register for fast access to pin

OpenCPU GPIO functions is too for Dallas and DHT sensor

as example ( this hal_xxx functions use Mediatek enumerations ) https://github.com/Wiz-IO/framework-quectel/blob/master/opencpu/bc66/SDK15/wizio/hal.c#L35

artursmet commented 3 years ago

Thanks for explanation, that makes a low of sense now. Do you have any idea why my setup doesn't work? I have tried several combinations of DHT/DS sensors with various GPIO setups, but I didn't managed to get the example code working in my case.

Did I read this correctly, the 9 / 28 PIN numbers are correct, when I connect the sensor to GPIO1 port?

Wiz-IO commented 3 years ago

these examples are the result of this discussion https://forums.quectel.com/t/bc66-gpio-pins-and-dallas-semi-temperature-sensor/4464

and is tested with Olimex board before to share it

define DALLAS_A_PIN 9 / select_arduino_pin /

define DALLAS_M_PIN 28 / select_mediatek_pin, see pinsMap[] variant_pins.c /

is this line https://github.com/Wiz-IO/framework-quectel/blob/master/arduino/variants/bc66-te-b/variant_pins.c#L36 the array line is Arduino enum

Wiz-IO commented 3 years ago

https://github.com/Wiz-IO/platformio-quectel-examples/blob/master/BC66_SDK/Arduino/BC66_A11_DS1820_DHT_GPIO/src/main.cpp#L3

in this case the level convertor generate noise ?!?! https://forums.quectel.com/uploads/default/original/2X/d/d2326859ab1e6b3f8983f587fcf3764b80919dd4.jpeg (image is from Quectel Forum discussion)

artursmet commented 3 years ago

So if I understood you correctly - the Olimex dev board has level converter, which is preventing the program to run properly and read the DS1820 sensor, right? Is there a way to disable the converter on the board? (I'm running the board in default mode, I didn't touch the 3.3V jumpers yet).

I re-wired my setup with new DS sensor and I got to the point where the program was able to read the sensor ID, but it stopped:

ID E2 1C 3F 80 5B E2 1A CC 
Init Error( 2 )
Init Error( 1 )
ID 00 00 00 00 00 00 00 00 
Init Error( 3 )

And now after reseting the module it keeps displaying the 00 ID

Wiz-IO commented 3 years ago

yep... i dont know why ( no answer from Olimex and Quectel )

try shortcut olimex output pin GPIO1/P26 to module phisical pin 26 ( is GPIO1 ) look hardware manual to eliminate level-convertor

or use Quectel Board - there is no level-convertors

artursmet commented 3 years ago

I'll try, thanks for all the replies!

Wiz-IO commented 3 years ago

YW btw: sorry now I am at HomeOffice and can not make "some" experiments ( for help )

artursmet commented 3 years ago

btw. one more question - I have found this photo - https://pbs.twimg.com/media/EZh7iu9WAAUjG9j?format=jpg&name=large

What did you made with the stock Olimex board to achieve it? Do you have some wiring schema?

Wiz-IO commented 3 years ago

Dallas sensor over Uart https://github.com/Wiz-IO/platformio-quectel-examples/tree/master/BC66_SDK/Arduino/BC66%20A10_DS1820_OLED