LED from PC

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
pezaxxx
Posts: 1
Joined: Wed Sep 27, 2017 6:31 am

LED from PC

Post by pezaxxx » Wed Sep 27, 2017 7:07 am

Hello,

I would like to know how to drive the LED through the tkinter from the PC.
It may be necessary to write some script into the main.py board and then run it through the script in the PC.
Everything works, but when we turn on LED 1 and turn on LED 2, only the LED will remain on 2. When sending data to the board, the LED will flash and I do not want to.
my script for PC:

import pyboard
import time
from tkinter import *

pyb = pyboard.Pyboard('/dev/tty.usbmodem1432')

def led1_on():
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(1).on()')
pyb.exit_raw_repl()

def led1_off():
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(1).off()')
pyb.exit_raw_repl()

def led2_on():
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(2).on()')
pyb.exit_raw_repl()

def led2_off():
# LED2 = pyb.LED(2).off()
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(2).off()')
pyb.exit_raw_repl()

led_control_window= Tk()
led_control_window.geometry('270x200+200+200')

btn1=Button(led_control_window,text="LED1 ON",
command=led1_on).place(x = 60, y = 40,
width=70, height=40)
btn2=Button(led_control_window,text="LED1 OFF",
command=led1_off).place(x = 60, y = 90,
width=70, height=40)
btn3=Button(led_control_window,text="LED2 ON",
command=led2_on).place(x = 140, y = 40,
width=70, height=40)

btn4=Button(led_control_window,text="LED2 OFF",
command=led2_off).place(x = 140, y = 90,
width=70, height=40)

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: LED from PC

Post by dhylands » Wed Sep 27, 2017 4:08 pm

If you're using the raw REPL to send commands then that will be the problem.

Everytime you enter the raw repl, the board goes through a soft-reset cycle, which will turn all of the LEDs off.

I wrote a json-ipc library https://github.com/dhylands/json-ipc which you can run on the MicroPython board and send commands to it in the form of JSON messages.

Post Reply