0

so I want to run a Arduino LCD shield with Python code..But after having some research on the Internet, I can not found any tutorial, some just give some basic code with LED.

And one things that how can I add a LCD library (LyquidCrystal.h in Arduino code) if i program in Python.

Thank you guys very much.

  • 2
    You cannot program an Arduino with Python – chrisl Nov 23 '19 at 11:32
1

It's like @chrisl wrote in the comments. You cannot program Arduino with python.

You can however upload an open source Firmata protocol implementation onto the Arduino and then write python code on your PC that will send commands to the Arduino by USB cable to tell it what to do.

This way you actually execute your code on PC, but control Arduino pins. Only drawback is that you need to have a PC connected to the Arduino at all times. This is not very practical.

There is a really nice tutorial here

Example python code looks like this:

import pyfirmata
import time

board = pyfirmata.Arduino('/dev/ttyACM0')
while True:
    board.digital[13].write(1)
    time.sleep(1)
    board.digital[13].write(0)
    time.sleep(1)

I'm afraid that only solution to controlling LCD shield this way without writing any C is to write the entire LCD library in python basing on pyfirmata calls to control the Arduino pins. It's not as hard as it sounds, and even a beginner could easily succeed.

| improve this answer | |
  • However, if the task is to run an existing Arduino LCD library, it has to run on the Arduino. If it needs data from a python script, it's questionable, whether firmata is the proper transport mechanism. And if that python script gets all data from the Arduino, one should consider to run that logic directly on the Arduino, instead of that generic firmata overhead. – DataFiddler Nov 23 '19 at 16:57
  • @DataFiddler Yes, if I can not program all things on Python..so I wonder that if there any ways to pass data from Python (for ex. "Hello World") to Arduino LCD sheild. – Q.H.Chu Nov 24 '19 at 0:22
  • As it's unclear to me what you want to outsource from Arduino to a Python node, I have no idea, whether pyfirmata or pyserial is your way to go. ( If at all, IMO ) – DataFiddler Nov 24 '19 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.