Is that code useable on an ESP32 board

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
RudiOnTheAir
Posts: 2
Joined: Wed Feb 19, 2020 7:40 am

Is that code useable on an ESP32 board

Post by RudiOnTheAir » Wed Feb 19, 2020 8:07 am

Hi

I would like to port that small programm to run on an ESP32.

It is using the accurate time to set an gpio on and of. On the Raspi i get the time from 3 ntp server.
On that ESP32 i would like to use in addition a gps receiver...

Is that possible? Thanks in advance...

Code: Select all

import time
from RPi import GPIO

LED_PIN = 40
SEQUENCE = [
    (1000, True),
    (2000, False),
    (7000, True),
    (3000, False),
    (5000, True),
    (2000, False),
]

PERIOD = sum(t for t, _ in SEQUENCE) / 1000.0  # in seconds

def main():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LED_PIN , GPIO.OUT)
    try:
        next_time = time.time()
        next_time -= next_time % -PERIOD
        while True:
            for delay, on in SEQUENCE:
                GPIO.output(LED_PIN, on)
                next_time += delay / 1000.0
                time.sleep(max(0, next_time - time.time()))
    finally:
        GPIO.cleanup()
	
if __name__ == '__main__':
    main()

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is that code useable on an ESP32 board

Post by jimmo » Wed Feb 19, 2020 8:53 am

Yes you could absolutely do this on esp32 - NTP and GPS are well supported.

RudiOnTheAir
Posts: 2
Joined: Wed Feb 19, 2020 7:40 am

Re: Is that code useable on an ESP32 board

Post by RudiOnTheAir » Wed Feb 19, 2020 1:57 pm

That sounds good.

I'm interested in this peace of hardware.

https://wesp32.com/

So i can test with ethernet for NTP timesync and gnss as fallback. What do you prefer for a gps (gnss) receiver to connect to?

Post Reply