chipKIT® Development Platform

Inspired by Arduino™

Max32 and basic io shield

Created Sat, 23 Mar 2013 20:32:36 +0000 by driedeker


driedeker

Sat, 23 Mar 2013 20:32:36 +0000

why do they not give you a scetch to test all the buttons etc as well as the clever demos. that way we can test it ait broke


driedeker

Sat, 23 Mar 2013 22:10:39 +0000

for everyone thats interested the chipkit reference manuel for this is in need of correction the button pins marked as 37 36 for on a uno are wrongly marked in the manual its says 79 80 and on mine its 80 81 so am I the only one to have this shield eaather mine is wrong or chipkit ref manual is.


JordanR

Mon, 25 Mar 2013 20:59:55 +0000

Hello driedeker,

Thank you for posting this. The reference manual pinout table has been fixed and will hopefully be updated on the website soon.

Best Regards,

Jordan Retz


driedeker

Mon, 25 Mar 2013 22:49:29 +0000

thanks for the good news Jordan

will keep an eye out for it :P


dboechler

Tue, 02 Apr 2013 23:11:35 +0000

I just picked up a Basic I/O Shield and am able to get the OLED working, but no Buttons or Slide switches work :(

What PINS should I be referencing in MPIDE?

const int LED0 = 26;
const int LED1 = 27;
const int LED2 = 28;
const int LED3 = 29;
const int buttonPin0 = 2;
const int buttonPin1 = 7;
const int buttonPin2 = 8;
const int buttonPin3 = 35;
int buttonState0 = 0;
int buttonState1 = 0; 
int buttonState2 = 0; 
int buttonState3 = 0;
 
void setup()
{
  pinMode(buttonPin0, INPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  digitalWrite(LED0, LOW);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
}
 
void loop()
{
  buttonState0 = digitalRead(buttonPin0);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3); 
  
  // check if the pushbutton is pressed.
  if (buttonState0 == HIGH) {    
    // turn LED on:   
    digitalWrite(LED0, HIGH);
    delay(1000);
  }
  else {
    // turn LED on:   
    digitalWrite(LED0, LOW);
    delay(1000);
  }
 
  // check if the pushbutton is pressed.
  if (buttonState1 == HIGH) {    
    // turn LED on:   
    digitalWrite(LED1, HIGH);
    delay(1000);
  }
  else {
    // turn LED on:   
    digitalWrite(LED1, LOW);
    delay(1000);
  }

  // check if the pushbutton is pressed.
  if (buttonState2 == HIGH) {    
    // turn LED on:   
    digitalWrite(LED2, HIGH);
    delay(1000);
  }
  else {
    // turn LED on:   
    digitalWrite(LED2, LOW);
    delay(1000);
  }
  
  // check if the pushbutton is pressed.
  if (buttonState3 == HIGH) {    
    // turn LED on:   
    digitalWrite(LED3, HIGH);
    delay(1000);
  }
  else {
    // turn LED on:   
    digitalWrite(LED3, LOW);
    delay(1000);
  }

  delay(100);
}

What's up?


dboechler

Wed, 03 Apr 2013 12:09:30 +0000

I too was totally confused on the Basic I/O Shield as buttons, switches and leds didn't make sense.

So I made a simple test script to get your head around it (including the correction on PIN numbers Driedeker pointed out)

const int LD8 = 77; //Middle of board
const int LD7 = 76;
const int LD6 = 75;
const int LD5 = 74;
const int LD4 = 73;
const int LD3 = 72;
const int LD2 = 71;
const int LD1 = 70; //Right side of board

const int BTN4 = 81; //LEFT side of board
const int BTN3 = 80;
const int BTN2 = 78;
const int BTN1 = 4; //Middle of board

const int SW4 = 79; //LEFT side of board
const int SW3 = 8;
const int SW2 = 7;
const int SW1 = 2; //Middle of board

int BTN1State = 0;
int BTN2State = 0; 
int BTN3State = 0; 
int BTN4State = 0;
int SW1State = 0;
int SW2State = 0; 
int SW3State = 0; 
int SW4State = 0;
 
void setup()
{
  pinMode(BTN1, INPUT);
  pinMode(BTN2, INPUT);
  pinMode(BTN3, INPUT);
  pinMode(BTN4, INPUT);
  pinMode(SW1, INPUT);
  pinMode(SW2, INPUT);
  pinMode(SW3, INPUT);
  pinMode(SW4, INPUT);
  pinMode(LD8, OUTPUT);
  pinMode(LD7, OUTPUT);
  pinMode(LD6, OUTPUT);
  pinMode(LD5, OUTPUT);
  pinMode(LD4, OUTPUT);
  pinMode(LD3, OUTPUT);
  pinMode(LD2, OUTPUT);
  pinMode(LD1, OUTPUT);
  digitalWrite(LD8, LOW);
  digitalWrite(LD7, LOW);
  digitalWrite(LD6, LOW);
  digitalWrite(LD5, LOW);
  digitalWrite(LD4, LOW);
  digitalWrite(LD3, LOW);
  digitalWrite(LD2, LOW);
  digitalWrite(LD1, LOW);
}
 
void loop()
{
  BTN1State = digitalRead(BTN1);
  BTN2State = digitalRead(BTN2);
  BTN3State = digitalRead(BTN3);
  BTN4State = digitalRead(BTN4);
  SW1State = digitalRead(SW1);
  SW2State = digitalRead(SW2);
  SW3State = digitalRead(SW3);
  SW4State = digitalRead(SW4); 
  
  // check if the pushbutton is pressed.
  if (BTN1State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD1, HIGH);
  }
 
  // check if the pushbutton is pressed.
  if (BTN2State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD2, HIGH);
  }

  // check if the pushbutton is pressed.
  if (BTN3State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD3, HIGH);
  }

  // check if the pushbutton is pressed.
  if (BTN4State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD4, HIGH);
  }
  // check if the pushbutton is pressed.
  if (SW1State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD5, HIGH);
  }
  // check if the pushbutton is pressed.
  if (SW2State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD6, HIGH);
  }
  // check if the pushbutton is pressed.
  if (SW3State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD7, HIGH);
  }
  // check if the pushbutton is pressed.
  if (SW4State == HIGH) {    
    // turn LED on:   
    digitalWrite(LD8, HIGH);
  }
}

Thanks Driedeker


driedeker

Fri, 05 Apr 2013 18:23:30 +0000

I did the same with a test scetch as mine was awal till i spotted the pin typos in the ref guide. :P


mickeybeau

Wed, 10 Apr 2013 14:35:23 +0000

i did the same test but sw2 does not reset ,for some reason that status of the SW2 is kept HIGH (after the first set to HIGH) even after i reload the code it is kept HIGH any idea? thanks Michel


driedeker

Mon, 15 Apr 2013 19:36:53 +0000

Try my test Sketch

// constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int buttonPin2 = 7; // the number of the pushbutton pin const int buttonPin3 = 8; // the number of the pushbutton pin const int buttonPin4 = 79; // the number of the pushbutton pin const int buttonPin5 = 4; // the number of the pushbutton pin const int buttonPin6 = 78; // the number of the pushbutton pin const int buttonPin7 = 80; // the number of the pushbutton pin const int buttonPin8 = 81; // the number of the pushbutton pin const int ledPin = 77; // the number of the LED pin const int ledPin2 = 76; // the number of the LED pin const int ledPin3 = 75; // the number of the LED pin const int ledPin4 = 74; // the number of the LED pin const int ledPin5 = 73; // the number of the LED pin const int ledPin6 = 72; // the number of the LED pin const int ledPin7 = 71; // the number of the LED pin const int ledPin8 = 70; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status int buttonState2 = 0; // variable for reading the pushbutton status int buttonState3 = 0; // variable for reading the pushbutton status int buttonState4 = 0; // variable for reading the pushbutton status int buttonState5 = 0; // variable for reading the pushbutton status int buttonState6 = 0; // variable for reading the pushbutton status int buttonState7 = 0; // variable for reading the pushbutton status int buttonState8 = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(ledPin5, OUTPUT); pinMode(ledPin6, OUTPUT); pinMode(ledPin7, OUTPUT); pinMode(ledPin8, OUTPUT);

// initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); pinMode(buttonPin6, INPUT); pinMode(buttonPin7, INPUT); pinMode(buttonPin8, INPUT);

}

void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. //if it is, the buttonState is HIGH: if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else { // turn LED off: digitalWrite(ledPin, LOW); } // read the state of the pushbutton value: buttonState2 = digitalRead(buttonPin2);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
} else { // turn LED off: digitalWrite(ledPin2, LOW); } // read the state of the pushbutton value: buttonState3 = digitalRead(buttonPin3);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState3 == HIGH) {
// turn LED on:
digitalWrite(ledPin3, HIGH);
} else { // turn LED off: digitalWrite(ledPin3, LOW); } //read the state of the pushbutton value: buttonState4 = digitalRead(buttonPin4);

//check if the pushbutton is pressed. //if it is, the buttonState is HIGH: if (buttonState4 == HIGH) {
//turn LED on:
digitalWrite(ledPin4, HIGH);
} else { //turn LED off: digitalWrite(ledPin4, LOW); } //read the state of the pushbutton value: buttonState5 = digitalRead(buttonPin5);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState5 == HIGH) {
// turn LED on:
digitalWrite(ledPin5, HIGH);
} else { // turn LED off: digitalWrite(ledPin5, LOW); } // read the state of the pushbutton value: buttonState6 = digitalRead(buttonPin6);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState6 == HIGH) {
// turn LED on:
digitalWrite(ledPin6, HIGH);
} else { // turn LED off: digitalWrite(ledPin6, LOW); } // read the state of the pushbutton value: buttonState7 = digitalRead(buttonPin7);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState7 == HIGH) {
// turn LED on:
digitalWrite(ledPin7, HIGH);
} else { // turn LED off: digitalWrite(ledPin7, LOW); } // read the state of the pushbutton value: buttonState8 = digitalRead(buttonPin8);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState8 == HIGH) {
// turn LED on:
digitalWrite(ledPin8, HIGH);
} else { // turn LED off: digitalWrite(ledPin8, LOW); } }


DandyDon

Thu, 25 Jul 2013 16:38:56 +0000

I just recieved my Max32, Network shield, & Basic I/O shield. I plugged the I/O shield into my Max32 board & powered them up. I tried running an example, IOShield_Oled_Demo, but got errors when I compiled the sketch.

#error "No Supported Board Defined"

I opened the file OledDriver.c & tried to find where the board being used is defined, but could not find it...

Any suggestions as to where to define the board/shield I plan on using?


Ian_B

Thu, 25 Jul 2013 17:58:45 +0000

Tried it on my end and had no problems. Did you select the MAX32 as your board? That error should only show up if the wrong board is defined under Tools>>Board.


DandyDon

Thu, 25 Jul 2013 19:01:20 +0000

I have selected the MAX32-USB for Serial under Tools-->Board. Should I be using a different Max32...?


DandyDon

Thu, 25 Jul 2013 19:06:30 +0000

Yes, that did it!! I changed the board to simply the Max32 & it loaded the sketch perfectly!

Thanks for your help!!


DandyDon

Thu, 19 Sep 2013 15:01:36 +0000

Is there a way to create a *.h file that defines the constants for the LEDs, switches & buttons on the Basic I/O shield & include this file in other sketches?


mikes

Thu, 19 Sep 2013 16:24:25 +0000

Is there a way to create a *.h file that defines the constants

Yes the easiest way is to make it a library. example: Basic_IO_Pins.h

#ifndef BASIC_IO_PINS_h
#define BASIC_IO_PINS_h
#include <WProgram.h>
#if defined(_BOARD_MEGA_)
#define LED1 8
#define LED2 9
#define SW1 18
#elif  defined(_BOARD_UNO_)
#define LED1 10
#define LED2 12
#define SW1 16
#elif  defined(_BOARD_UC32_)
#define LED1 14
#define LED2 16
#define SW1 21
#endif
#endif

keywords.txt

#######################################
# Syntax Coloring Map For BASIC_IO_PINS
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
#######################################
# Methods and Functions (KEYWORD2)
#######################################
#######################################
# Instances (KEYWORD2)
#######################################
#######################################
# Constants (LITERAL1)
#######################################
LED1(this is a tab)LITERAL1
LED2	LITERAL1
SW1	LITERAL1

Note: Not the correct pins I just made them up for the example edit: added multiple board definitions to example


DandyDon

Thu, 19 Sep 2013 17:29:15 +0000

Thanks, Mikes!!

What is the keywords.txt file for?


mikes

Thu, 19 Sep 2013 17:43:10 +0000

keywords.txt is for syntax highlighting if you want your defines colored. [color=#FFBF00]pinMode/color;[color=#008000] //without the file[/color] [color=#FFBF00]pinMode/color;[color=#008000] //with the file[/color]


DandyDon

Thu, 19 Sep 2013 19:16:02 +0000

OK. Thanks!

What are the requirements on file structure with regard to *.h files? Do they need to be in the same folder as the sketch? or a main include folder?


mikes

Thu, 19 Sep 2013 19:43:49 +0000

If you put the files in a library folder it will have syntax highlighting ..\mpide\libraries\Basic_IO_Pins #include <Basic_IO_Pins.h>

If you put the file in your sketch folder no keywords.txt it won't work #include "Basic_IO_Pins.h"


DandyDon

Thu, 19 Sep 2013 20:08:11 +0000

OK. Thanks again!!


DandyDon

Fri, 20 Sep 2013 18:30:58 +0000

OK. I got the keywords.txt file & BasicIOShield.h file created & stored in the directory ...mpide-0023-windows-20130715\libraries\chipKITBasicIOShield.

I opened MPIDE & imported the files. Looks good so far! I'll play around with it & see what I can do.

Thanks again!!


DandyDon

Fri, 20 Sep 2013 21:28:22 +0000

Not working... I got errors about the way I defined the LEDs I think. I'll try to post my code later (late Friday afternoon must not be good for writing code...)


mikes

Fri, 20 Sep 2013 22:47:50 +0000

You might also try the library folder in with your sketches C:\Users\Your Name\Documents\mpide\libraries (this is the default location) or the core libraries mpide-0023-windows-20130715\hardware\pic32\libraries