Simple question: How to read from IO
-
Sorry for the stupid question (neither google nor the forum search helped me):
I could not find a Gcode command to read one of my IO? How is it possible? I would assume that there is a gcode command witch returns a json...
For Marlin I found M43, but for duet it seem to be different....
-
Ok it seems to be easy:
just call
M308 S4
to get the sensor value.
-
Use any or all of:
- M577 to wait for an input pin to be in a particular state
- M581 (and possibly M582) to cause some action to take place when the state of an input pin changes
- In RRF 3.01, M409 or conditional GCode to query the value of sensors.inputs[n] for some n
-
@dc42 Thanks: I will try
M409 K"sensors.inputs"
Maybe some feedback: Does it make sense to include a small example in the gcode documentation, that I will be the last person who is asking? Normally the people search for "read io"/ "read voltage" / "get sensor value" and its hard for them/me to find something in the documentation.
-
@JBisc, you will need to create a GPIO port attached to your chosen pin using M950 with the J option, before you can see it in sensors.inputs.
Yes an example would help. If you tell us what you are trying to achieve, we could use that as an example.
-
@dc42 I believe that my scenario is not a very common one. I am working on a complex algorithm to measure the 2D/3D-geometry of my workpiece. The algorithm is to complex to implement it in gcode, therefor I implement a supersiving software layer in python (think about a python-gcode wrapper) which calculates the algorithm. Then, the supervising software optimize the 3dprinter.
-
Curious side question: Where are you running the Python?
-
Visions of automated probing are running through my head .... could be as simple as setting resolution for x and y, setting a range of x and y and telling the printer to measure every point. Might be painfully slow but hey, it could do it. Put every value into a spreadsheet which can then be imported into Fusion360 and presto, the beginnings of a model. Obviously some hand work is required.
As a side question, just exactly how accurate is a 3D scanned object? Are the scanned objects dimensionally accurate or could manually probing increase accuracy?
In any case, having a probing tool head for quality control of a printed object might be interesting. -
@Danal currently on the RPI. Ohhhh Danal, you are the author of the wrapper which I use. Great to meet you here! Thanks for your amazing work. I started with forking your project (https://github.com/DanalEstes/PythonDSF)
-
@JBisc said in Simple question: How to read from IO:
@Danal currently on the RPI. Ohhhh Danal, you are the author of the wrapper which I use. Great to meet you here! Thanks for your amazing work. I started with forking your project (https://github.com/DanalEstes/PythonDSF)
There's another choice now as well: DuetWebAPI. Requires network connectivity to the printer (can, but not required to, run on the attached Pi) and also abstracts away V2 to V3 differences.
-
@dc42 said in Simple question: How to read from IO:
@JBisc, you will need to create a GPIO port attached to your chosen pin using M950 with the J option, before you can see it in sensors.inputs.
If I use M950 by
M950 J4 C"io4.in"
I can get only a ditgital input by calling
M409 K"sensors.inputs"
which is not what i want.
If I define my sensor by
M308 S4 P"io4.in" Y"linear-analog" A"MySensor" F0
I don't know a method to return my analog sensor value (to the RPI). Does somebody has an idea?
-
Ok it seems to be easy:
just call
M308 S4
to get the sensor value.
-
@JBisc said in Simple question: How to read from IO:
I don't know a method to return my analog sensor value (to the RPI). Does somebody has an idea?
When you say "return to the Pi", what would happen? Push? Pull? what code reads it or responds or...
What do you want to happen?
-
I implemented in the following way now:
My python programm on the RPI sends
M308 S4
and i parse the response (on the RPI)
Sensor 4 (MySensor) type Linear analog using pin io4.in, reading 3.8, last error: success, unfiltered, range 0.0 to 1.0
to get the sensor value
-
You could also get it by using M409 to request that value from the object model.
-
@dc42 said in Simple question: How to read from IO:
M409
I remember that you posted in another post that analog values are not included in the current object model
-
@JBisc said in Simple question: How to read from IO:
@dc42 said in Simple question: How to read from IO:
M409
I remember that you posted in another post that analog values are not included in the current object model
Raw analog inputs are not included, but the readings from configured sensors are:
20/04/2020, 09:55:19 m409 k"sensors.analog[0].lastReading" {"key":"sensors.analog[0].lastReading","flags":"","result":21.5}
-