Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Add ADC (analog voltage) support to gpio library #143

Merged
merged 3 commits into from
Jun 12, 2024

Conversation

jamisonderek
Copy link
Contributor

@jamisonderek jamisonderek commented Jun 9, 2024

What's new

  • ADC (Analog to Digital Conversion) is now available in the firmware. This change exposes the functionality to JavaScript. You can run the program without any wires and should see some voltage levels. If you connect 0-2 Volt output to pins 2,3,4 (A7, A6, A4) the program will display the voltage in millivolts. You can also just attach a wire to A7 and touch it to see some additional voltage displayed.

For the reviewer

  • I've uploaded the firmware with this patch to a device and verified its functionality
  • I've confirmed the bug to be fixed / feature to be stable

@jamisonderek
Copy link
Contributor Author

I just realized that people new to the API might call readAnalog("PA7") without first calling startAnalog(), which would assert on NULL handle. This update will return an error message instead. I'm not sure if the type of error should be MJS_SYNTAX_ERROR or something else?

@jamisonderek
Copy link
Contributor Author

NOTE: Don't directly touch the input wires to 3V3 as that will exceed 2.0 volts reference voltage.

An easy way to test the script is to put wires in pin A7 [pin2], A6 [pin 3], and A4 [pin 4], GND [pin 8] and 3V3 [pin 9]. Run the script, each pin should be reading about 100mV. Touch one of the input wires (A7, A6 or A4) and the data should change. With another finger touch ground and the value should decrease. Remove your finger from ground and instead touch one of the input wires and 3V3 and the data should increase. Do not exceed 2.0 volts, but if you do, use GND and the pin to help pull it back to normal levels (you can even touch the pin directly to GND).

@Willy-JL Willy-JL added the feature New feature or request label Jun 11, 2024
@Willy-JL
Copy link
Member

hi! thanks for the PR :D

just FYI, the checkboxes in "For the reviewer" section are for us to keep track of testing on the PR, please leave them blank when submitting

looks pretty good! i made some minor changes to how handle state is managed, it mirrors what badusb, usbdisk, and serial do: error if you try to start when already started, or stop when not started. also used INTERNAL_ERROR, since those follow that pattern aswell

@Willy-JL Willy-JL merged commit b3e1009 into Next-Flip:dev Jun 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants