r/ArduinoProjects • • Aug 31 '24

How do I display some graphics on a Waveshare 1.5inch RGB OLED?

Hello!

I recently buyed a Waveshare OLED, and I understood nothing in the instructions.

First of all, why when I edit in Arduino IDE(I hate C) it doesn't display anything???

Even if I don't change the code, and try to re-upload the demo, I have a blank screen!

If I don't connect to PC, I don't get this issue.

And another question, can I program it in Python?

Thanks in advice.

0 Upvotes

6 comments sorted by

1

u/SUKyeNan Aug 31 '24
  1. Blank Screen After Uploading Code:

    • When you upload the code via the Arduino IDE and get a blank screen, it could be due to a mismatch in the configuration or incorrect initialization of the display. Ensure that the correct libraries are included and initialized properly in your code.

    • Verify the connections and ensure the correct pins are defined in the code if you’ve altered any settings.

  2. No Issues When Not Connected to PC:

    • If the issue only occurs when connected to the PC, it might be related to power supply issues or serial communication. Make sure that the OLED display is getting sufficient power when connected via USB.

  3. Programming in Python:

    • Yes, you can program the Waveshare OLED in Python, especially if you prefer Python over C/C++. You would typically use a platform like Raspberry Pi or another microcontroller that supports Python (e.g., with CircuitPython or MicroPython). Waveshare usually provides libraries and examples for Python as well.

    • For Raspberry Pi, you would use the SPI or I2C interface, and Waveshare might offer a Python library to simplify the process.

Troubleshooting Steps:

  • Code Examples: Start with the demo code provided by Waveshare without making changes. If it works, gradually introduce your modifications.

If you want to dive into Python, look for Waveshare’s documentation or examples related to Raspberry Pi and Python to get started. This might offer a smoother experience if you’re not comfortable with Arduino IDE and C.

1

u/Background-Offer2321 Sep 01 '24

Thank you! The problem was in incorrect init. But another question, can I program in Python with Arduino? Like Pyserial or something else?

1

u/SUKyeNan Sep 01 '24

Yes, you can interact with an Arduino board using Python through libraries like pySerial or pyFirmata. However, you won’t be directly programming the Arduino in Python; instead, you’ll use Python to communicate with the Arduino while the Arduino runs a program written in C/C++ (often using the Arduino IDE). Here’s how you can do it:

  1. Using pySerial:

    • Purpose: pySerial is a Python library that allows you to communicate with the Arduino over a serial connection.

    • How it Works: You write a C/C++ program (sketch) on the Arduino that waits for commands or sends data via the serial port. Then, you write a Python script using pySerial to send and receive data.

    Example Arduino Sketch:

    void setup() {
        Serial.begin(9600);  // Start the serial communication at 9600 baud rate
    }
    
    void loop() {
        if (Serial.available() > 0) {
            String data = Serial.readString();  // Read the incoming data
            Serial.println(„Received: „ + data);  // Send a response back to Python
        }
    }

    Example Python Script Using pySerial:

    import serial
    import time
    
    arduino = serial.Serial(port=‚COM3‘, baudrate=9600, timeout=.1)  # Replace ‚COM3‘ with your port
    
    def send_data(data):
        arduino.write(bytes(data, ‚utf-8‘))
        time.sleep(0.05)
        response = arduino.readline()
        return response.decode(‚utf-8‘)
    
    while True:
        data = input(„Enter data to send: „)
        response = send_data(data)
        print(„Arduino responded with:“, response)
  2. Using pyFirmata:

    • Purpose: pyFirmata is a Python library that works with the Firmata protocol. Firmata is a generic protocol for communicating with microcontrollers from software on a host computer.

    • How it Works:You upload the Firmata firmware to the Arduino using the Arduino IDE. Then, you can control the Arduino’s pins and read sensors using Python.

    Steps to Use pyFirmata:

    1. Upload Firmata: In the Arduino IDE, go to File -> Examples -> Firmata -> StandardFirmata and upload this to your Arduino.

    2. Install pyFirmata:*Install the Python package using pip:

      pip install pyfirmata
    3. Control the Arduino:

    Example Python Script Using pyFirmata:

    from pyfirmata import Arduino, util
    import time
    
    board = Arduino(‚COM3‘)  # Replace ‚COM3‘ with your port
    
    while True:
        board.digital[13].write(1)  # Turn on the LED on pin 13
        time.sleep(1)
        board.digital[13].write(0)  # Turn off the LED on pin 13
        time.sleep(1)

Summary:

  • pySerial: Ideal for simple serial communication where you send and receive data between the Arduino and Python.

  • pyFirmata: Best for more complex control where you want to directly manipulate Arduino pins and peripherals from Python.

1

u/Background-Offer2321 Sep 02 '24

Thank you very much! But can I program exactly Waveshare OLED RGB 1.5inch on it?