IO Module tutorial or FAQ?

Expansion modules and attachments
Post Reply
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: IO Module tutorial or FAQ?

Post by rimai »

The modified version is posted a few posts back. That's the one you need to upload.
The original is here:

Code: Select all

#include <Wire.h>
#include <avr/wdt.h>

byte IOports[] ={
  3,5,6,9,10,11};

byte IOOut=0;
void setup()
{
  wdt_enable(WDTO_1S);
  Wire.onReceive(NULL);
  Wire.onRequest(requestEvent);
  Wire.begin(9);
  for (int a=0;a<6;a++)
  {
    pinMode(IOports[a],INPUT);
    digitalWrite(IOports[a],HIGH); //pull up resistor
  }
}

void loop()
{
  wdt_reset();
}

void requestEvent() {
  IOOut=0;
  for (int a=0;a<6;a++)
  {
    IOOut+=digitalRead(IOports[a])<<a; //pull up resistor
  }
  Wire.write(IOOut);
}
Roberto.
Piper
Posts: 296
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA

Re: IO Module tutorial or FAQ?

Post by Piper »

Roberto,

I've had some issues with my buttons on the IO module and while troubleshooting I realized that I need some sort of "debounce" for the button presses. I'm pretty sure I have that all sorted out but that led me to a couple of schematics that make me think I'm going about the buttons all wrong and wanted to run this by you.

From my Arduino/Electrical newb-ness, I pictured the buttons I am using with the I/O module as simply completing the circuit between the port it's plugged into (0-6) and the ground on the module. I am not using any resistors this way.

Here is what is making me second guess that:
Image
Image

Looking at the schematics above, it looks like I should be plugging the +5v from the Arduino board into one side of the button and go to ground via a resistor on the other side. I would tie in the I/O pin on the resistor side of the button to check if I'm HIGH or LOW.

Sorry for the nomenclature but I'm still an electronics newb and don't know how to properly phrase that. I hope you can get the gist of what I'm saying.

Am I OK doing it my way I have been doing it? It has been working fine other than that odd button behavior that the debounce should fix.

[EDIT]
Or are you already taking care of that under the hood on the module?
[/EDIT]

~Charlie
Last edited by Piper on Thu Jul 04, 2013 6:23 pm, edited 1 time in total.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: IO Module tutorial or FAQ?

Post by rimai »

Well, I really is up to you to decide whether you want to use pull-up or pull-down and whether to use external resistors or the internal resistors.
Check here:
http://makezine.com/2009/03/05/understa ... ulldown-r/
I just picked pull-up and internal resistor for simplicity.
In the setup() section of the code, you will see this:

Code: Select all

  for (int a=0;a<6;a++)
  {
    pinMode(IOports[a],INPUT);
    digitalWrite(IOports[a],HIGH); //pull up resistor
  }
That's where I chose to use internal resistors and pulled them up, which will force the pins high on default state.
Because we are not using the pins on any load, the internal pull-up resistors should work just fine.
They are 100K if I'm not mistaken.
So, we are doing the opposite of what the design above is doing, which is pull-down with external resistor.
I think this is where you got the diagram above, but check this for debounce:
http://arduino.cc/en/Tutorial/Debounce
Roberto.
Piper
Posts: 296
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA

Re: IO Module tutorial or FAQ?

Post by Piper »

Thanks, Roberto. Basically you have it all taken care of under the hood. I just need to do the debounce and keep it physically set up the way I have it.

~Charlie
Veeresh
Posts: 5
Joined: Sat Mar 01, 2014 7:45 pm
Location: Singapore

Re: IO Module tutorial or FAQ?

Post by Veeresh »

Hi Roberto
I am planning to integrate the Reef Angel to my home automation system such that an alarm in the RA can play some message in the house AV system. I need to config the IO Expansion module to send out voltage to a relay. I read this post and wondering how to update the IO expansion module firmware. I opened up the IO module and there is no connector to plug in the USB-TTL. Can you guide me on this matter ?


Veeresh
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: IO Module tutorial or FAQ?

Post by rimai »

Which version of board do you have?
Roberto.
Post Reply