Closed virtq closed 6 years ago
Method SetAnalogReportMode
is used to command an Arduino board to send a continuous stream of sampled values. GetPinState
retrieves a pin's single value.
I cannot reproduce the issue.
The same think happens to me. I always receve 0 value when i execute getPinState.
I also have similar problems. I see a tremendous number of posts with the same questions. I feel the solidsoils library is well written. However, to date, I have not been able to find anyone providing information on using the analog side of solidsoils. All responses are vague and without example. There are a multitude of videos and text articles on the digital side. However, the digital side is rarley in question.
It would be very helpful if someone could provide a short example in C#/C#.NET that reads an analog value from Analog input pin A0 on the Arduino UNO using Firmata. This would be most helpful. The internet and myself would be most grateful.
ZEEEEEEEEEEROOOOOOOOOOOO, THIS CODE GIVES ZERO:
PinState result = session.GetPinState(14);
UpdateStatusListBox(result.Value.ToString());
Can anyone here do their job properly?
This file from the SolidSolis repo contains a full working example of both Analog and Digital signal processing:
https://github.com/SolidSoils/Arduino/blob/master/Solid.Arduino.Run/Program.cs
Everything that starts with this:
static void SimpelTest
And until the end of the file.
But out of the box, it is also incomplete (sets up the callbacks, but starts listening for only digital pins).
To get it to work for analog pins, people need to toss in this line somewhere inside static void SimpelTest
:
firmata.SetAnalogReportMode(5, true);
Which then makes that code magically trigger the callback private void Session_OnAnalogStateReceived
which contains the correct recording of an analog pin.
After that I need to solve the problems with parallel threads and busy open Arduino connections which is still work in progress.
This is the answer I was looking for. I'm a hero here.
@zoopyserg, this SimpelTest is part of a basic and informal tool I only created for testing the software. I hope to fix the documentation soon and add some proper examples though.
Besides, IFirmata.SetAnalogReportMode
does not trigger the callback. It sends a message to the Arduino board telling it to start or stop sending analog state change messages. The ArduinoSession
object routes these messages to the OnAnalogStateReceived
event.
Regarding the open connections: it is the Windows OS that is keeping serial port connections open for some time. There is no (easy) way to work around that behaviour as it is hidden somewhere in the system32 dll's. Serial port connections are closed asynchronously by the OS, so even when you close the connection in .NET, behind the scenes it still remains open for some time.
I'm trying to get a value from an analog input. I have tested with a standard arduino sketch together with a potentiometer and I'm getting values between 0 - 1023 as expected. However when I try to do the same using SolidSoils library I get the value 0 every time. It can recognize values from digital ports though. Maybe I don't understand how to use the library correctly. Do I need to set AnalogReportMode to true for the channel?
Using Firmata version 2.5.2.
Code: