pimoroni / unicorn-hat

Python library for Unicorn pHAT and HAT. 32 or 64 blinding ws2812 pixels for your Raspberry Pi
https://shop.pimoroni.com/products/unicorn-hat
MIT License
370 stars 131 forks source link

Simple example for Arduino #48

Closed mralexgray closed 8 years ago

mralexgray commented 8 years ago

I know it is possible... but I have been too dumb to figure out what is needed (libraries, etc) / how to connect the hat - to an Arduino - for simple usage.

Any example / help would be much appreciated!

Gadgetoid commented 8 years ago

You can use Adafruit's NeoPixel library to drive UnicornHAT from an Arduino. Use the VCC, DIN and GND pins on the edge of UnicornHAT to connect to 5V, a data pin, and Ground respectively and you're good to go: https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library

xTauv commented 6 years ago

Gadgetoid, I'm really new to this. So I want to attach the UnicornHAT to an Arduino Uno. Could you simplify the adafruit NeoPixel code for me? I'm very confused.

xTauv commented 6 years ago

image1

Should I use the NeoMatrix library instead?

Gadgetoid commented 6 years ago

Looks like you're wiring the right pins to the right connections on the HAT, but without a more robust connection you'll probably find it doesn't work. Since the ends of those wires are square, and the holes on the PCB are round, the contact surface is at best negligible.

You can either:

a. Solder the wires, or a female header to the Unicorn HAT to make a better connection or b. Plug the wires directly into the relevant connections on the 40-pin header. See: https://pinout.xyz/pinout/unicorn_hat which gives a top down view of which pins to use (looking from the top of the HAT)

Then to init the library on Arduino:

#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
void loop() {
  // put your main code here, to run repeatedly:
  strip.setPixelColor(11, 255, 0, 255); 
  strip.show();
}