tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
587 stars 180 forks source link

request for ds18b20 driver #489

Open kellyfitzy opened 1 year ago

kellyfitzy commented 1 year ago

Hi,

I'm a novice programmer looking for a tinygo ds18b20 driver to use with Raspberry Pi Pico W. Willing to test. Have used various ds18b20 golang drivers on Raspberry Pi Nano, etc. Thanks in advance!

dn-kolesnikov commented 1 year ago

I'm done my library for 1-wire In current moment I’m adding support for ds18b20 In few days I’m going to push it to my GitHub Tested for RP pico

kellyfitzy commented 1 year ago

thanks!

On Sat, Dec 17, 2022 at 8:19 AM Dmitry N. Kolesnikov < @.***> wrote:

I'm done my library for 1-wire In current moment I’m adding support for ds18b20 In few days I’m going to push it to my GitHub Tested for RP pico

— Reply to this email directly, view it on GitHub https://github.com/tinygo-org/drivers/issues/489#issuecomment-1356322915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6IVRXMGETAETXFIXF76ELWNXRZ3ANCNFSM6AAAAAAS3I3XEE . You are receiving this because you authored the thread.Message ID: @.***>

dn-kolesnikov commented 1 year ago

Hi,

I'm a novice programmer looking for a tinygo ds18b20 driver to use with Raspberry Pi Pico W. Willing to test. Have used various ds18b20 golang drivers on Raspberry Pi Nano, etc. Thanks in advance!

https://github.com/dn-kolesnikov/tinygo-drivers.git

first commit so far, it only works with a single sensor on the bus. no docs, no tests. :no_good: the rest is in the process see example...

kellyfitzy commented 1 year ago

Thanks, I'll check it out.

On Mon, Dec 26, 2022 at 3:16 AM Dmitry N. Kolesnikov < @.***> wrote:

Hi,

I'm a novice programmer looking for a tinygo ds18b20 driver to use with Raspberry Pi Pico W. Willing to test. Have used various ds18b20 golang drivers on Raspberry Pi Nano, etc. Thanks in advance!

https://github.com/dn-kolesnikov/tinygo-drivers.git

first commit so far, it only works with a single sensor on the bus. no docs, no tests. 🙅 the rest is in the process see example...

— Reply to this email directly, view it on GitHub https://github.com/tinygo-org/drivers/issues/489#issuecomment-1365101161, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6IVRUWVYIKGNZYSRBVYK3WPF5CBANCNFSM6AAAAAAS3I3XEE . You are receiving this because you authored the thread.Message ID: @.***>

matveynator commented 1 year ago

Hi, I'm a novice programmer looking for a tinygo ds18b20 driver to use with Raspberry Pi Pico W. Willing to test. Have used various ds18b20 golang drivers on Raspberry Pi Nano, etc. Thanks in advance!

https://github.com/dn-kolesnikov/tinygo-drivers.git

first commit so far, it only works with a single sensor on the bus. no docs, no tests. 🙅 the rest is in the process see example...

Could you pull to tinygo-drivers when ready and stable? Thank you very much!

conejoninja commented 1 year ago

Hello @dn-kolesnikov , thanks for your work, as @matveynator said, please make a pull request to the repo so we can properly review it.

I do have some DS18B20 laying around (the waterproof version), and will gladly review/test it.

One thing I notice, it that the ReadTemperature looks like this

func (d Device) ReadTemperature() (Temperature, error) {

It would be great if it has the same signature as other temperature sensor in the repository: temperature should be int32, and it should be milliCelsius instead of Celsius. That makes any temp. sensor interchangeable, and you could replace one with another without much effort.

func (d *Device) ReadTemperature() (temperature int32, err error) {
dn-kolesnikov commented 1 year ago

Hello @dn-kolesnikov , thanks for your work, as @matveynator said, please make a pull request to the repo so we can properly review it.

I do have some DS18B20 laying around (the waterproof version), and will gladly review/test it.

One thing I notice, it that the ReadTemperature looks like this

func (d Device) ReadTemperature() (Temperature, error) {

It would be great if it has the same signature as other temperature sensor in the repository: temperature should be int32, and it should be milliCelsius instead of Celsius. That makes any temp. sensor interchangeable, and you could replace one with another without much effort.

func (d *Device) ReadTemperature() (temperature int32, err error) {

ok, I'll try to do a refactoring within a couple of weeks

dn-kolesnikov commented 1 year ago

Hi, I'm a novice programmer looking for a tinygo ds18b20 driver to use with Raspberry Pi Pico W. Willing to test. Have used various ds18b20 golang drivers on Raspberry Pi Nano, etc. Thanks in advance!

https://github.com/dn-kolesnikov/tinygo-drivers.git first commit so far, it only works with a single sensor on the bus. no docs, no tests. 🙅 the rest is in the process see example...

Could you pull to tinygo-drivers when ready and stable? Thank you very much! Ok, I’ll do it! —- до конца января постараюсь реализовать все ROM функции и зареквестить в мастер

dn-kolesnikov commented 1 year ago

Hello @dn-kolesnikov , thanks for your work, as @matveynator said, please make a pull request to the repo so we can properly review it.

I do have some DS18B20 laying around (the waterproof version), and will gladly review/test it.

One thing I notice, it that the ReadTemperature looks like this

func (d Device) ReadTemperature() (Temperature, error) {

It would be great if it has the same signature as other temperature sensor in the repository: temperature should be int32, and it should be milliCelsius instead of Celsius. That makes any temp. sensor interchangeable, and you could replace one with another without much effort.

func (d *Device) ReadTemperature() (temperature int32, err error) {

Corrected the function, you can check it

conejoninja commented 1 year ago

Hello @dn-kolesnikov ,

I went ahead and moved your code to a new branch in the drivers repository as I was having some issues with the import paths of your code : https://github.com/conejoninja/drivers/tree/onewire (this is my personal repo). I added smoke tests and added it to the README.md devices' list too. Fixed some typo in the comments/doc.

Feel free to make any modification you want to, or make your own PR. I did it because I plan to use the ds18b20 in one example at a talk at #FOSDEM (4th February), so I need this working as soon as possible.

I still can't get it to work, I'm getting the following error

Read OneWire ROM
Error: OneWire. No devices on the bus.

I'm using Arduino Nano33 IOT, connected to pin D13 and a 4.7K resistor between D13 and 3.3V pins. My hardware setup works fine with this C library : https://github.com/milesburton/Arduino-Temperature-Control-Library but strange enough not with this other : https://github.com/matmunk/DS18B20

dn-kolesnikov commented 1 year ago

Hi @conejoninja, I have uno, nano and micro boards. I will check on these boards and let you know the results. on Monday (09.01.2023) after 10 am (GMT+5) I will be in the office and do all the checks.

conejoninja commented 1 year ago

After a brief talk and some more tests, the driver is working properly and what was wrong with my setup was powering the sensor directly from the board. It's still a bit strange but this is what I got:

Thanks for your help sorting this out. Great work with this driver.

dn-kolesnikov commented 1 year ago

Hi there!

https://github.com/dn-kolesnikov/tinygo-drivers.git

The driver functionality is ready for use. There are functions for searching devices on the bus (up to 32), reading the temperature in raw values and in Celsius /1000. I use 5 sensors to control the electric heating of my house. Who is ready to add this driver to the main branch?

conejoninja commented 1 year ago

Hello @dn-kolesnikov thanks for the update and your work.

Just one question about it:

dn-kolesnikov commented 1 year ago

Right now, you just create one DS18B20 device and handle the different sensors passing the romId around, could it make sense to use a DS18B20 device for each sensor? When

I thought about how to make the implementation of various devices around the 1-Wire bus more elegant. In the current version, we are not creating a separate DS18B20 device, we are creating an interface that matches the 1-Wire bus methods. I wanted to combine everything into one onewire package with the implementation of a single device “Device” containing only the pin number. since for work we need only a pin and supports, and all methods for various devices are called through a prefix, for example DS18B20_ReadTemperature () and so on ...

perhaps, with the expansion of functionality, we will do refactoring. if there are thoughts on how to improve the existing implementation, I'm open to suggestions.