mitra42 / webForth

Forth for the web - implemented in JS and other web technologies
https://www.mitra.biz/forth/console.html
GNU Affero General Public License v3.0
27 stars 1 forks source link

Arduino: Add pin control and interupts #63

Closed mitra42 closed 3 years ago

mitra42 commented 3 years ago

Add some words to manage pins.

Some examples of other approaches

mitra42 commented 3 years ago

From https://arduino-forth.com/article/FORTH_FlashForth_pinsDefinition defPIN ( PORTx mask -- | word -- mask port high ( PORTx mask -- ; uses mset ) low ( PORTx mask -- ; uses mclr ) output ( pinmask portadr -- ; sets 1 address below portadr) input ( pinmask portadr -- ; clears 1 address below portadr) : pin@ ( pinmask portaddr -- fl ; reads 2 addresses below to see whether input using mtst

mitra42 commented 3 years ago

From WiringPi: https://github.com/kristopherjohnson/wiringPi_gforth 18 CONSTANT LEDpin LEDpin OUTPUT pinMode LEDpin HIGH digitalWrite See also https://github.com/kristopherjohnson/wiringPi_gforth/blob/master/wiringPi.fs (more specific to Pi)

mitra42 commented 3 years ago

Note ESP8266 tests performed on Lolin D1 mini pro (like Wemos) and Arduino on Arduino UNO Arduino C functions are documented in https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/ mode = INPUT | OUTPUT | INPUT_PULLUP INPUT=0 OUTPUT=1 INPUT_PULLUP=2 on Arduino & ESP8266 pinMode(pin, mode) digitalWrite(13, HIGH);

Also: https://www.arduino.cc/en/Tutorial/Foundations/DigitalPins. summary:

Also: https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/ val = AnalogRead(pin) ; range 0..1023

Also https://randomnerdtutorials.com/esp8266-adc-reading-analog-values-with-nodemcu/ which suggests only Analog pin on ESP8266 is A0

See https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

Most of the ESP8266 development boards have a built-in LED. This LED is usually connected to GPIO2 = D4 On Lolin board BUILTIN_LED is defined as 2

mitra42 commented 3 years ago

Straw-person steps

mitra42 commented 3 years ago

Closing as split subtasks into own issues:

See Analog input #101 See Analog write #102 See Interrupts #103