GitJer / Some_RPI-Pico_stuff

Some experiments I did with the Raspberry Pi Pico

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Porting to micropython

nameoftherose opened this issue · comments

Thank you for making your work available.
I am trying to convert the limited_1_wire code to micropython.
I have a couple of questions:

  • What are you using the side_set pin for?
  • In the reset_and_check() function you state 'assuming only one [sensor] is present'. Although I do not see how one could implement the 1Wire search algorithm in PIO, I think your code could be used to read the temperature from multiple sensors using the match ROM command. One would have to obtain the sensors' addresses during initialization by bit-banging. Do you see any obstacle to that?

As I lack resources to compile the program myself, please consider releasing the UF2 file.
Thank you.

The side_set pin controls the direction (is it input or is it output) of the data pin. Since it is a one-wire protocol you need to set the direction to input (side 0) for reading and output (side 1) for writing. In the cpp code on lines 55 to 62 you'll see that there is only one pin used for set, out, in and sideset.

What could be done (haven't tried this) is to attach the first sensor, read its ROM, then disconnect it and attach the second sensor, read its ROM, etc. The ROMs can be stored in the program and then used in match ROM. In that way you could address them one by one.

I have started implementing the search algorithm in cpp, but many things got/are in the way of finishing it. The only additional thing (I think) that is needed to be added in PIO is to read two bits and write one bit. This is necessary for the search algorithm that sets a bit and then reads the response bit and the complement of the response bit. Reading two bits can be achieved by adding a new point of entry in the PIO code that sets x to 2 and then jumps to read_byte_loop. Similar for sending one bit.

You say you cannot compile the code. But my projects are always about finding out how things can be done in principle. If you really want to do something with it, you'll have to change it to your needs.

Thank you very much.

  • Concerning side_set, pin direction can also be changed using set pindirs. I assume, by using side_set you make an optimization and save a few instructions. Nice.
  • Concerning matchROM, that was my idea too. In micropython I also have the option of using the builtin ds18x20.scan method to find the sensors' addresses
  • I meant my PC does not have enough disk space to install the C/C++ SDK.