Jump to content

Chipkit Cmod + Pmodoled For Light-sensitive Resistor


LariSan

Recommended Posts

This is a simple project that uses the PmodOLED + the chipKIT Cmod and a light resistor circuit on a breadboard. 
 

 



http://youtu.be/go6Sbrblfa8
 

 

 

It requires that you have the PmodOLED library downloaded off the product page: 
 
and a (chipKIT) CK1 Cmod: http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-CMOD
 
 
(need a breadboard, 10KOhm resistor, light resistor, wires and USB Cable to replicate the project)
 
Once you have the OLED library in your MPIDE Sketchbook "Libraries folder" http://chipkit.net/started/learn-basics/party-libraries/
 
then, you can use this sketch code:
 
 

/*Larissa Swanland for the Digilent MakerSpace.
You are free to use the code to share with others and make awesome things...
just don't be a jerk and make sure to share your project!
chipKit CMOD  Header J1 (note '1' for pin 1) */

#include <DSPI.h>
#include <OLED.h>

OledClass OLED;


const int analogInPin= 26;
const int analogOutPin=12;


int sensorVal= 0;
int sensorRead=0;
int lastVal=0;


void setup()
{
  OLED.begin();
  Serial.begin(9600);

}

void loop()
{
  
  /*read the analog sensor*/
  
  sensorVal=analogRead(analogInPin);
  sensorRead= sensorVal; //map(sensorVal,0,1023,0,600);
  
  //Serial.println(sensorRead); //debugging
  
  delay(200); //let sensor settle


/*to display on PmodOLED*/

  int lastVal;         //declare integer
  char buff[5];      //declare character array
  String readVal;    //declaring string


readVal=String(sensorRead); //convert integer to string
readVal.toCharArray(buff,5); //pass value of string to character array

//Serial.println(buff);  //debugging



if (1.10*lastVal!=sensorRead){ // 10% deifference to change the update
  sensorRead=lastVal; 
  
    OLED.clearBuffer();
    OLED.setCursor(0, 0);
    OLED.putString("Value:");
    OLED.setCursor(0, 5);
    OLED.putString(buff);
  
 }else{
   
    OLED.clearBuffer();
    OLED.setCursor(0, 0);
    OLED.putString("No Change");
    OLED.setCursor(0, 5);
    OLED.putString(buff);
 }
}

 

If you have any errors (using a Mac and keep getting a <sysattribs.h> file missing, please see this thread: 
 

 

 

Here's the circuit wiring. 

 
16394592701_58157ac7bb_c.jpgchipKITcmod-lightsensor by laraswanland, on Flickr

Link to comment
Share on other sites

  • logansam featured and unfeatured this topic

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...