Getting Busy with Projects and the chipKIT Basic I/O Shield

Happy Tuesday, everyone! I tend to get excited about products that enable beginners to be really creative, and today’s product highlight is one I think is worth getting excited about!

 

 

A few things that I really like about the shield:

Add chipKIT, USB Cable, MPIDE to get started right away!
Add chipKIT, USB Cable, and MPIDE to get started right away!

The shield is an add-on board that was designed to be used with the chipKIT Uno32, the uC32, or the Max 32.

The Basic I/O Shield connects to the headers sitting on top of a chipKIT Uno32
The Basic I/O Shield connects to the headers sitting on top of a chipKIT Uno32.

Once you connect the Basic I/O Shield to the chipKIT board of choice and download MPIDE (referenced in the video), then a world of projects are instantly at your fingertips.  This is because of all of features that are built-into the shield.

Just a few project ideas using the multiple I/O's on the shield. Combining them  makes even more powerful projects!
Just a few project ideas using the multiple I/Os on the shield. Combining them makes even more powerful projects!

Perhaps the best part about the Basic I/O Shield is that you don’t have to spend time wiring up all of the individual components. This is great for teachers who have limited course time, if you are doing a workshop focused on the programming, or if you want to spend your time wiring up something non-traditional… like 12V Analog LEDs (see the end of post for demo)!

Here are a few projects that we’ve done with the I/O Shield, but we’d love to see other project ideas!


 

Having the 8 LEDs Run back and forth in sequence (using an Array):

/*Arrays
 
 Demonstrates the use of  an array to hold pin numbers
 in order to iterate over the pins in a sequence. 
 Lights multiple LEDs in sequence, then in reverse.
 
 Unlike the For Loop tutorial, where the pins have to be
 contiguous, here the pins can be in any random order.
 
 The circuit:
 * on an Arduino and chipKIT uno32 LEDs from pins 2 through 7 to ground
 * on the chipKIT I/O Expander Shield it's pins 26-33
 
 created 2006
 by David A. Mellis
 modified 5 Jul 2009
 by Tom Igoe  modified by Larissa Swanland Digilent Inc-2014
This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Array
 */

int timer = 100;           // The higher the number, the slower the timing.
int ledPins[] = { 
  33, 32, 31, 30, 29, 28, 27, 26 };       // an array of pin numbers to which LEDs are attached
int pinCount = 8;           // the number of pins (i.e. the length of the array)

void setup() {
  int thisPin;
  // the array elements are numbered from 0 to (pinCount - 1).
  // use a for loop to initialize each pin as an output:
  for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
    pinMode(ledPins[thisPin], OUTPUT);      
  }
}

void loop() {
  // loop from the lowest pin to the highest:
  for (int thisPin = 0; thisPin < pinCount; thisPin++) { 
    // turn the pin on:
    digitalWrite(ledPins[thisPin], HIGH);   
    delay(timer);                  
    // turn the pin off:
    digitalWrite(ledPins[thisPin], LOW);    

  }

  // loop from the highest pin to the lowest:
  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { 
    // turn the pin on:
    digitalWrite(ledPins[thisPin], HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(ledPins[thisPin], LOW);
  }
}


 

 Using the Analog Potentiometer to Change the Number of LEDs: 

(in the first video) potentiometer

/*Digilent Inc. 
Larissa Swanland 2014
Code written to use with chipKIT Uno32/UC32 + the IO Expander Shield
focus with 10K Potiometer and 8 LED's
to see the pin-outs please look at page 8 in IO Expander reference guide:
https://digilentinc.com/Data/Products/CHIPKIT-BASIC-IO-SHIELD/chipKIT%20Basic%20IO%20Shield_rm.pdf*/

const int potPin= A0; //Pin that the 10K Pot is attached to

//LED Outputs using an Array, please see Array Code for example
int i; 
int led[] = {33, 32, 31, 30, 29, 28, 27, 26 };      // an array of pin numbers to which LEDs are attached

//variables that will change:
int potRead= 0; 
int potVal= 0;  //Mapped Value of Pot
int lastPot=0; //last value of Pot Stored


void setup(){
  pinMode(potPin, INPUT);  // declare Pot as input
  //intialize the LED pins
  for (int i=0; i < 9; i++){
    pinMode(led[i], OUTPUT);
  }
  Serial.begin(9600); 
}

void loop(){
  potRead=analogRead(potPin);            //read Analog Value attached to Pot
  potVal= map(potRead, 0, 1023, 0, 8);   //map the value from 0-1023 to 0-7 (coincides with LED Array)
                                         
                                         //compare old reading to new reading
  if (potVal!= lastPot) {                //if current value is different from old
    lastPot = potVal;                    //then store the new value
    Serial.print(potVal);                //for debugging using Serial monitor
    for (int i=0; i<potVal+1; i++){
      digitalWrite(led[i],HIGH);
    }
  } else {
    for(int i= potVal-1; i>=0; i--){
      digitalWrite(led[i], LOW);
    }
  }

}

 

RGB Analog Strip:

Fade sequence for the RGB Strips
Fade automatically between colors in sequence for the RGB strips.

 

/*Digilent Inc. 
Larissa Swanland 2014- Fade colors for RGB Strips
Connect Analog RGB to individual FET channels and power to shared 12V Power Supply (see photo)*/
#define REDPIN 5
#define GREENPIN 3
#define BLUEPIN 9
 
#define FADESPEED 5     // make this higher to slow down
 
void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
}
 
 
void loop() {
  int r, g, b;
 
  // fade from blue to violet
  for (r = 0; r < 256; r++) { 
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  } 
  // fade from violet to red
  for (b = 255; b > 0; b--) { 
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  } 
  // fade from red to yellow
  for (g = 0; g < 256; g++) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 
  // fade from yellow to green
  for (r = 255; r > 0; r--) { 
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  } 
  // fade from green to teal
  for (b = 0; b < 256; b++) { 
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  } 
  // fade from teal to blue
  for (g = 255; g > 0; g--) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  } 
}

 

Combining Switches + Potentiometer + Analog RGB Strips:

/*Digilent Inc
Larissa Swanland 2014
S4- is the on-off switch
S1-3 are the switches that control the channel on the RGB LEDs
The Analog Pot will control brightness*/

const int potPin= A0; //Pin that the 10K Pot is attached to
const int red = 5; // Pin 3 when LED Strip is connected
const int blue= 3; // Pin 5 when LED Strip is connected
const int green= 9; // Pin 6 When LED Strip is connected
const int sw1= 35;
const int sw2= 8;
const int sw3= 7;
const int sw4= 2; 

int s1,s2,s3,s4; 
int potRead= 0;
int potVal=0;  //Mapped Value of Pot-- intensity
int lastPot=0; //last value of Pot Stored

void setup(){
  pinMode(sw1, INPUT);
  pinMode(sw2, INPUT);
  pinMode(sw3, INPUT);
  pinMode(sw4, INPUT);
  
  pinMode(potPin, INPUT);  // declare Pot as input
  
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
  
  Serial.begin(9600);
}

void loop(){
  //read the switch values
  s1= digitalRead(sw1); //red
  s2= digitalRead(sw2); //green
  s3= digitalRead(sw3); //blue
  s4= digitalRead(sw4); //on or off 
  potRead=analogRead(potPin); //read Analog Value attached to Pot
  potVal=map(potRead, 0, 1023, 0, 256); //map the pot to the value of RGB Brightness
  
   if(potVal!=lastPot){
   lastPot= potVal;
   Serial.print(potVal);}
  
  if(s4==0)// the last switch is on
 {
  analogWrite(red, 0);
  analogWrite(green,0);
  analogWrite(blue, 0);
 }else{
   analogWrite(red, s1*potVal);
   analogWrite(green,s2*potVal);
   analogWrite(blue,s3*potVal);
 }
  
}

Combine all of the sketches together!





/*Digilent Inc
Larissa Swanland 2014
S4- will make the LEDs cycle through a routine (there is a slight delay)
S1-3 are the switches that control the channel on the RGB LEDs
The Analog Pot will speed of the cycle*/


const int potPin= A0; //Pin that the 10K Pot is attached to
const int red = 5; // Pin 3 when LED Strip is connected
const int blue= 3; // Pin 5 when LED Strip is connected
const int green= 9; // Pin 6 When LED Strip is connected
const int sw1= 35;
const int sw2= 8;
const int sw3= 7;
const int sw4= 2; 

int s1,s2,s3,s4; 
int potRead= 0;
int potVal=0;  //Mapped Value of Pot-- intensity
int lastPot=0; //last value of Pot Stored
int fadespeed=1; //fadespeed

void setup(){
  pinMode(sw1, INPUT);
  pinMode(sw2, INPUT);
  pinMode(sw3, INPUT);
  pinMode(sw4, INPUT);
  
  pinMode(potPin, INPUT);  // declare Pot as input
  
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
  
  Serial.begin(9600);
}

void loop(){
 
   
    
  //read the switch values
  s1= digitalRead(sw1); //red
  s2= digitalRead(sw2); //green
  s3= digitalRead(sw3); //blue
  s4= digitalRead(sw4); //on or off 
  potRead=analogRead(potPin); //read Analog Value attached to Pot
  potVal=map(potRead, 0, 1023, 0, 256); //map the pot to the value of RGB Brightness
  
   while(potVal!=lastPot){
   lastPot= potVal;
   Serial.print(potVal);
 }
   if (s4==1)// the last switch is on
 {
   
  fade(); 
  
 }else{
   analogWrite(red, s1*potVal);
   analogWrite(green,s2*potVal);
   analogWrite(blue,s3*potVal);
 }
}
  
void fade(){
   int r, g, b; 
   fadespeed= 255/potVal; 
   
  // fade from blue to violet
  for (r = 0; r < 256; r++) { 
    analogWrite(red, r);
    delay(fadespeed);
  } 
  // fade from violet to red
  for (b = 255; b > 0; b--) { 
    analogWrite(blue, b);
    delay(fadespeed);
  } 
  // fade from red to yellow
  for (g = 0; g < 256; g++) { 
    analogWrite(green, g);
    delay(fadespeed);
  } 
  // fade from yellow to green
  for (r = 255; r > 0; r--) { 
    analogWrite(red, r);
    delay(fadespeed);
  } 
  // fade from green to teal
  for (b = 0; b < 256; b++) { 
    analogWrite(blue, b);
    delay(fadespeed);
  } 
  // fade from teal to blue
  for (g = 255; g > 0; g--) { 
    analogWrite(green, g);
    delay(fadespeed);
  } 
}


Be the 1st to vote.

About Larissa Swanland

I'm a bit of an electronics-education evangelist. After all, Education is how we learn about the world. Electronics make the world better. Engineers change the world. So more engineers that know how to design and create electronics? That's the kind of world I want to help create.

View all posts by Larissa Swanland →

7 Comments on “Getting Busy with Projects and the chipKIT Basic I/O Shield”

  1. This is very cool!!
    I just got this kit and I just tried the First two programs here on this pages to verify the that the board works and it does!!
    Thank you for posting this!!

    However I can not get the OLED Demo to work to verify that the display works.
    Can you post a program that I can copy and paste like the other one for the OLED?

    I did everything I was supposed to do I believe that is correct as described from the CHIPKIT website and your video (using Windows instead) tutorial using the demo file from Diligent and it fails to work.

    I get a compilation error, so it never gets to the point to upload the program to the uc32.

    Many of the other demos work as well so I know the uc32 is working properly.
    I just got this so I need to verify that if the OLED is working or not, in the case if that I need to send it back to the supplier.

    Thanks!! Jer 😀

  2. Hi geraldfryjr,

    I have a guess at what the problem might be, but what compilation error are you receiving? Is it saying something about not being able to find “IOShieldOled.h”?

    Thanks,
    James COlvin

  3. Yes, Thank you for the reply.
    I did finally get it to work after I had figured out what directory to put the Library files in.

    There was also an issue with the version of MPIDE that I was using as well switching to an earlier version I got it to work and then later I switched to the latest Beta version and it worked as well.
    But, What was supposed to be the current version at the time of my post did not work correctly.
    Sorry for the late response as I had mean’t to post this info and version numbers I am using.

    Once I got it to compile correctly everything worked on the Basic I/O board and Uc32!!
    I can’t even explain how ecstatic I was and still am at this cool little system.

    I had even found another demo for the OLED the other day and it worked without a hitch.

    Now I am trying to get the Linux version of MPIDE to work but I haven’t had much luck with it.

    I haven’t messed with it in a month or so, so I forget all of the details right now.
    I will try to get back here shortly with all of the details I have found so that it will quickly help others at getting theirs to work to if anyone has any issues.

    Thanks !!!!

    jer 🙂

  4. I found my data for using a PC.

    When you install MPIDE it creates a folder called MPIDE and in this folder is where your Sketch’s or projects go and are saved.
    But this is not were you put the libraries for the Basic I/O shield like it says in the video.
    Maybe for a MAC but not a PC.

    The Libaries for the Basic I/O go in a folder where all of the original MPIDE files are kept as follows,

    MPIDE/Hardware/Pic32/libraries/ “the 3 needed Basic I/O resources go here”

    Then the Compiler will find them and compile without errors.
    I don’t remember whether or not I got it to work in linux since I had wiped that version of my distro out and started all over due to an error that was caused when I installed MPLABX Version 2.26.
    Since then I am using ver 2.30 and it works okay I think.
    I have had some issues with some programs I have written in assembly in ver. 2.15 and failed in ver. 2.26 and seems to be working in ver. 2.30 as well.
    But I am still having issues with my C programs in MPLABX 2.30 in Linux but that is another issue and I haven’t had the time lately to iron that out yet.
    It is just another can’t find the libraries issues there too.
    Meanwhile it works fine in windows.
    I use XP64, Win7 and Ultimate Edition 4.3 Linux (KDE) for my choice of OS’s

    Cheers!!

    jer 🙂

  5. Hi jer, I apologize for the delay.

    I’m not familiar with MPLABX and how all that will go, but I am more familiar with MPIDE. You can put the Basic I/O Shield libraries in the created “mpide” folder. You would need to create a folder within the mpide folder called “Libraries” and place them in there (as mentioned in the video). Then, what you would need to do is open up MPIDE itself and go to File->Preferences. You then need to change the Sketchbook location to where you are storing all of your sketches. In my case thats Users\jcolvin\Documents\mpide for both a windows 7 and windows 10. Then it will be able to find all of the library files (once you have restarted MPIDE).

    Let me know if you have any more questions!

    Thanks,
    James Colvin

Leave a Reply

Your email address will not be published. Required fields are marked *