FarmBot / farmbot-mqtt-py

An MQTT wrapper for FarmBot written in Python
MIT License
42 stars 24 forks source link

Tool identification using pins L and K #11

Closed kulbir-ahluwalia closed 2 years ago

kulbir-ahluwalia commented 2 years ago

Hi,

Currently, FarmBot uses pin C (Digital pin 63) for identifying whether a tool is mounted or not.

However in our case, sometimes the sequence is not completed fully and hence the "mounted_tool" variable does not have the correct value.

  1. Is it possible to use the pins L and K for identifying exactly which tool is mounted?
  2. Could you please let us know which digital pins are L and K connected to?

Since L and K would effectively give us 2-bit encoding with the combinations 00, 01, 10 and 11, we can identify the nozzle, weeder, seeder and soil sensor. It would be helpful for our case. (Credits for the idea ==> Michael)

Many thanks for considering my request.

Regards, Kulbir

kulbir-ahluwalia commented 2 years ago

Considering the pinout references: https://genesis.farm.bot/v1.5/Extras/reference/pinout-references.html

Could you please help us with the following questions if possible:

  1. Pin F = A10 or D64? Is the pin meant to be used as an analog input or as a digital read/write pin?
  2. Pin G = D42. Can this be used as a digital read pin?
  3. Pin H = D44 or PWM. Can this be used as a digital read pin?
  4. Pin L = D53 or SS. Can this be used as a digital read pin? What does SS mean here?
  5. Pin K = D52 or Serial Clock (SCK). Can this be used as a digital read pin?

Sorry for too many questions but I want to make sure that we do not fry up the raspberry pi or the farmduino board.

Thank you so much!

Regards, Kulbir

gabrielburnworth commented 2 years ago

For FarmBot Genesis v1.5, UTM pins F through L are not connected to anything (and UTM pin E is connected to D48, which is available for use). See this UTM pin mapping table for details. (For the latest FarmBot Genesis version, refer to the pin mapping table on this page.)

To connect any of the UTM pins to Farmduino pins of your choice:

  1. (If applicable, remove pin jumpers from the pin you want to use.)
  2. Connect one end of a jumper wire the UTM pin on the bottom row on the board with the letter label you wish to use. This will provide a connection all the way through the board, UTM cable connector, UTM cable, and UTM to the pogo pins that contact the tool electrical connection screws.
  3. Connect the other end of the jumper wire to the Farmduino pin you want to read and/or write. This will likely be one of the pins in the IO section of the board. For the FarmBot Genesis v1.5, the following pins are available: 2, 3, 18, 19, 38, 42, 48, 60(A6), 61(A7), 62(A8). For other models, refer to the IO pin labels on your board.

UTM_connections

Any of the available Farmduino pins in the IO and UTM sections can safely be used as digital read/write pins (bot.read_pin(pin_number) and bot.write_pin(pin_number, pin_value) in this library or the READ SENSOR and CONTROL PERIPHERAL commands in the web app).

You may need to add a LUA command (where pin_number can be replaced with your choice of Farmduino pin number, i.e., 48) before reading the pin value if it seems like it's not behaving properly. If needed, it can be added as a LUA command in the web app or bot.lua(lua_string) in this library. For additional information about the Lua function, see this page.

set_pin_io_mode(pin_number, "input_pullup")

Good luck with your project, and consider sharing it in the forum!

kulbir-ahluwalia commented 2 years ago

Thank you so much for your help. We really appreciate it. We will try this and get back asap. Thanks again!!!

kulbir-ahluwalia commented 2 years ago

Hi Gabriel,

We were able to use 2 pins, F and G which were connected to pins D19 and D42 respectively. This helps us to identify the tools when they are mounted.

but surprisingly, the "read pin" function does not really update the value the first time we call it. It only updates the value when we call it for a second time. Even then, the value is very unstable and is true only 7 out of 10 times.

Do you know what might be going on here? Is D19 a pin we can use?

Looking forward to your help. Thank you!!

gabrielburnworth commented 2 years ago

D19 is a pin you can use, but an unstable value might mean the pin needs to be pulled. Did you set the pin IO mode for that pin to "input_pullup"? Do the correct values reflect that mode (0 for connected and 1 for disconnected)?

kulbir-ahluwalia commented 2 years ago

Thanks for your help. It would be great if you could help us with some questions:

  1. Is there a function from farmbot-py that can achieve the lua version of result, error = set_pin_io_mode(19, "input_pullup")?

  2. Do we have to set the input mode to "input_pullup" before reading a pin everytime? We already added 3.3 kilo-ohm pullup resistors in series to limit the current to 1.5mA.

  3. As of now, when we do self.bot.read_pin(pin, pin_mode="digital"), we have to do it two times in a row in order for the pin values to actually update. It does not update the first time. Any suggestions for this?

We highly appreciate your prompt support. Thank you!

gabrielburnworth commented 2 years ago
  1. There's only: bot.lua('result, error = set_pin_io_mode(19, "input_pullup")')
  2. If you already have pull-up resistors and you are getting the pin read behavior you want without setting the pin mode, then no, you don't need to set the pin mode.
  3. After the read_pin command, does every bot state update sent after that have old data, or is it just the first bot state update that has old data?