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

Arduino: Add pin control and interupts #63

Closed
mitra42 opened this issue Nov 25, 2020 · 5 comments
Closed

Arduino: Add pin control and interupts #63

mitra42 opened this issue Nov 25, 2020 · 5 comments

Comments

@mitra42
Copy link
Owner

mitra42 commented Nov 25, 2020

Add some words to manage pins.

  • Ideally in a manner that would be independent of the board used
  • ideally compatible with other people's approaches (so code written for webForth would work on e.g. FlashForth)
  • ideally incorporate interrupts
  • use the C primitives in Arduino IDE

Some examples of other approaches

@mitra42 mitra42 added the NextUp label Nov 25, 2020
@mitra42 mitra42 changed the title Arduino: Add pin control Arduino: Add pin control and interupts Dec 6, 2020
@mitra42 mitra42 added the Arduino label Mar 4, 2021
@mitra42
Copy link
Owner Author

mitra42 commented Mar 8, 2021

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
Copy link
Owner Author

mitra42 commented Mar 8, 2021

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
Copy link
Owner Author

mitra42 commented Mar 8, 2021

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:

  • Defaults to INPUT

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
Copy link
Owner Author

mitra42 commented Mar 8, 2021

Straw-person steps

  • Try standard blinkplay sketch on Arduino Uno
  • Try standard blinkplay sketch on ESP8266 - required using BUILTIN_LED
  • Modify sketch to get values INPUT OUTPUT INPUT-PULLUP, HIGH, LOW and define Forth cosntants
  • Define constants HIGH LOW
  • Presuming same pins, define some forth words
    • pinMode ( pin mode -- )
    • digitalWrite ( pin HIGH | LOW )
  • Write simple blink test using loop and delay and test on Arduino & ESP8266
    • : blink BEGIN 500 ms 13 0 digitalWrite 500 ms 13 1 digitalWrite AGAIN ;

@mitra42
Copy link
Owner Author

mitra42 commented Mar 9, 2021

Closing as split subtasks into own issues:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant