Chipkit Cmod + Pmodoled For Light-sensitive Resistor

Recommended Posts

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



It requires that you have the PmodOLED library downloaded off the product page: 
and a (chipKIT) CK1 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"
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()


void loop()
  /*read the analog sensor*/
  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
    OLED.setCursor(0, 0);
    OLED.setCursor(0, 5);
    OLED.setCursor(0, 0);
    OLED.putString("No Change");
    OLED.setCursor(0, 5);


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 post
Share on other sites
  • logansam featured and unfeatured this topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now