Simple Python Code

I was wondering does anyone OR can anyone tell me a simple python code to test my arduino 1280? I just want to maybe learn how to blink one of my led's that are connected to my pwm outputs.

Thank you

An arduino will not run python code AFAIK. The language is C++ (based).
Can you state more clearly what you want?

Just that, I just wanted to test my lights using python. I saw this page Arduino Playground - Python, and thought it was possible. But I am not under UNIX i am under windows 7. I wanted to try and start building a python script that would allow me to control my lights or arduino.

this is indeed possible, but your question was unclear.

You need to create the following configuration:

PC with Python ---- serial line----- Arduino with C++ sketch --- LED

The python script sends commands over the serial line, the arduino receives them, interprets them and switches the LED

Arduino code for led 13 controlled by serial commands (character 1 and 0 )

void setup()
{
  Serial.begin(115200);
  pinMode(13, OUTPUT);
}

void loop()
{
  if (Serial.avalable())
  {
    char c = Serial.read();
    if (c == '1') digitalWrite(13, HIGH);
    if (c == '0') digitalWrite(13, LOW);
    // other commands here
  }
}

furthermore you need to make a small pythonscript that uses pySerial to send the chars over the line.

Hi! I've created a Python application to communicate with Arduinos, maybe you find it usefull... I don't have a Window PC to test it, so, I don't known if it even works on it. If don't work, you could install an Ubuntu with VMPlayer o VirtualBox.

The project is on GitHub: GitHub - hgdeoro/py-arduino-proxy: [renamed to py-arduino] Communicate with Arduino from Python (DEPRECATED! Please see py-arduino).

It's very easy to use, and there is a simple UI (very simple at the moment):
- YouTube.

To blink the onboard LED, you would use something like:

import time
from arduino_proxy import ArduinoProxy
proxy = ArduinoProxy('/dev/ttyACM0')
proxy.pinMode(13, ArduinoProxy.OUTPUT)
while True:
	proxy.digitalWrite(13, ArduinoProxy.HIGH)
	time.sleep(0.5)
	proxy.digitalWrite(13, ArduinoProxy.LOW)
	time.sleep(0.5)

Hi

  1. Install pyserial
    pyserial · PyPI

This blink code is working:

Arduino:

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop()
{
  while (Serial.available() > 0){
    char c = Serial.read();
    if (c == '1') digitalWrite(13, HIGH);
    if (c == '0') digitalWrite(13, LOW);
  }
}

Python:

>>> import serial
>>> import time
>>> arduino = serial.Serial('COM4',9600)
>>> for i in range(10):
	arduino.write(1)
	time.sleep(1)
	arduino.write(0)
	time.sleep(1)

-Fletcher