This project makes use of the Grove OLED 96x96 display to present a mini-slideshow. Pictures on your computer are transferred to the OLED via a Processing script, and will cycle through them as many times as you choose.
void setup() { //Allow communication to OLED Wire.begin();
//Allow Serial communication between Freetronics Eleven and Computer Serial.begin(28800);
//Initialise the OLED SeeedGrayOled.init(); //Clear the OLED display SeeedGrayOled.clearDisplay(); //Set to vertical mode - horizontal mode doesn't work with this example SeeedGrayOled.setVerticalMode();
}
void loop(){ //Listen for Serial comunication while (Serial.available()>0) { // Read data and send directly to the OLED sendMyData(Serial.read()); counter++;
//When counter reaches 4608 pixels, the picture is complete. if(counter>4607){ //Insert delay to allow viewing of picture. delay(4000); Serial.println("End of Transmission");
//Reset the counter for the next picture counter=0; } } }
// This function was adapted from the SEEED Gray OLED driver so that // character bytes could be sent directly to the OLED. void sendMyData(unsignedchar Data){ Wire.beginTransmission(SeeedGrayOLED_Address); // begin I2C transmission Wire.send(SeeedGrayOLED_Data_Mode); // data mode Wire.send(Data); Wire.endTransmission(); }
// This function was adapted from the SEEED Gray OLED driver so that // commands could be sent directly to the OLED. // NOT USED IN THIS EXAMPLE *********************** void sendMyCommand(unsignedchar Cmd){ Wire.beginTransmission(SeeedGrayOLED_Address); // begin I2C communication Wire.send(SeeedGrayOLED_Command_Mode); // Set OLED Command mode Wire.send(Cmd); Wire.endTransmission(); // End I2C communication }
import processing.serial.*; /* Needed for Serial Communication */
/* Global variables */ Serial comPort; String [] comPortList; String comPortString; PImage img; char[] tempGrey=newchar[4609]; int startOffset=0; ArrayList picNames; int curLoop=1; int totalPics=0; int curPicNum=0; boolean toggleSend=true; boolean sendBouncer=true;
//Change maxLoops to a number > 1 if you want the pictures to loop. int maxLoops=1;
void setup() { //The size of the display is critical (must match the OLED) size(96, 96); //setup Serial comPortList = Serial.list(); if(comPortList.length>0){ //baud rates greater than 28800 may produce unexpected results comPort = new Serial(this, comPortList[0], 28800); comPort.bufferUntil('\n'); } else{ println("NO COM PORTS AVAILABLE"); }
//Create an Array of pictures picNames=new ArrayList(); picNames.add("Picture1.bmp"); picNames.add("Picture2.bmp"); picNames.add("Picture3.bmp"); picNames.add("Picture4.bmp"); // for more pictures just keep adding them to the list. //The actual pictures must be located in the data folder of this project. //Select Sketch/Add File to add the files to this folder. //Make sure that the name of pictures match the names above.
//Get the total number of pictures added totalPics=picNames.size(); }
sendImage((String)picNames.get(curPicNum)); //Send the picture to the OLED toggleSend=false; //temporarily stop sending any more pictures until authorised curPicNum++; //increment in preparation for the next picture
if(curPicNum==totalPics){ curPicNum=0; //go back to the first picture curLoop++; //increment the loop counter } if(curLoop>maxLoops){ sendBouncer=false; //Stop any further looping println("ANIMATION COMPLETE"); } } }
void sendImage(String imgName){ img = loadImage(imgName); image(img,0,0,width,height); loadPixels(); int counter=0; for (int x = 0; x < width; x=x+2) { for (int y = 0; y < height; y++) { counter++; int PixLoc = x + y*height; // this reads down then across2. //Left pixel nibble int Pix1=(round((red(pixels[PixLoc])*0.222+green(pixels[PixLoc])*0.707+blue(pixels[PixLoc])*0.071)))/16; //Right pixel nibble int Pix2=(round((red(pixels[PixLoc+1])*0.222+green(pixels[PixLoc+1])*0.707+blue(pixels[PixLoc+1])*0.071)))/16; //Shift the byte <<4 for the left pixel nibble int PixShift1=Pix1<<4; //Combine both nibbles to form a byte int PixFin = PixShift1+Pix2; byte PixByteFin=byte(PixFin); //Assign this byte to the tempGrey array tempGrey[counter] = char(PixByteFin); } } sendSerial(tempGrey); //Send the image data through the Serial COM Port/ }
//This function will send the byte/Char array to the Freetronics //Eleven or Arduino. void sendSerial(char[] Data){ for(int i=0; i<4608; i++){ //Needs an offset to get picture to align to screen properly //only needs to do this once. if(startOffset==0){ i=i+6; startOffset++; } //Send the picture data to the Freetronics Eleven / Arduino comPort.write(Data[i]); } }
//This function will wait for a response from the Freetronics //Eleven or Arduino before sending any further pictures. void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); if (inString != null) { println(inString); toggleSend=true; // Allow the next picture to be sent } }
Please note: that you must use the Arduino IDE version 023 until Seeed Studio update their driver for this OLED. Their current driver is not compatible with later versions of Arduino IDE.
Have you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This site and this document proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. The...
Guest Post Disclaimer This is a guest post by the EasyEDA team. I would like to thank EasyEDA for providing this tutorial for everyone to enjoy. All information within this post was provided by EasyEDA. Description None of us could deny the fact that we would love with to play with LED’s and lighting stuff. I love to play with LED’s and create attractive lighting effects. This project was a result of such an attempt where I created a stunning RGB light effect using the popular development platform Arduino Nano. Let’s see the circuit, code and instruction on building this project: Parts Required: An EasyEDA account (free) Arduino Nano (or compatible board) LED strip Dupont wire connectors Custom control board Image source: EasyEDA Ardui...
FIVE MINUTE TUTORIAL Project Description: Sending Hex values to an Arduino UNO This simple tutorial will show you how to send Hexadecimal values from a computer to an Arduino Uno. The "Processing" programming language will be used to send the HEX values from the computer when a mouse button is pressed. The Arduino will use these values to adjust the brightness of an LED. Learning Objectives To Send Hexadecimal (Hex) values from a computer to the Arduino Trigger an action based on the press of a mouse button Learn to create a simple Computer to Arduino interface Use Arduino's PWM capabilities to adjust brightness of an LED Learn to use Arduino's analogWrite() function Create a simple LED circuit...
Comments
Post a Comment