2.f. Writing Sketches for the Wixel Shield

Writing sketches for the Wixel shield is as easy as using the standard serial library to transmit and receive serial data. Note that when first enabling the serial port, you might receive an invalid serial byte as a result of noise on the serial lines. You can keep the Wixel from receiving this noise byte by delaying for ten milliseconds before and after calling Serial.begin(), like this:

Serial.begin(115200); // change this baud rate to the baud rate you set on your Wixel

Example Serial Communication Sketch

Here is a sketch (based off of the example physical pixel sketch) that demonstrates wireless serial communication between an Arduino and a computer:

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(115200); // *** NOTE: change this to the baud rate you set on your Wixel
  Serial.println("Wireless Physical Pixel");
  Serial.println("Send 'H' to turn on the LED and 'L' to turn off the LED.");
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED is on");
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
      Serial.println("LED is off");

If you paste this code into an empty sketch, you should be able to wirelessly upload it to your Arduino and use the serial monitor to communicate with your Arduino. In the serial monitor, you should see instructions for how to use the sketch.

Serial monitor connected to an Arduino running the Wireless Physical Pixel sketch.

Related Products

Wixel Shield for Arduino
Wixel Shield for Arduino, v1.1
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors