Author Topic: Configuring Inputs & Outputs on $50 Bot  (Read 2071 times)

0 Members and 1 Guest are viewing this topic.

Offline VegaObscuraTopic starter

  • Robot Overlord
  • ****
  • Posts: 153
  • Helpful? 6
Configuring Inputs & Outputs on $50 Bot
« on: December 26, 2010, 12:25:24 AM »
I'm trying to get the hang of adding new sensors and actuators to my $50 bot, and I'm having trouble getting digital pins to work as input.  To my understanding, all you have to do is set the pin to input and then call PORT_IS_ON.  If the port is high, PORT_IS_ON will return true, and if the port is low it will return false.

So to set pins 0-3 as output and 4-7 as input you would go into SoR_Utils.h and set

DDRD = 0x0F

Then to check if the port is high or low you would just say

if(PORT_IS_ON(PORTD, 4))
{
  printf("Port D pin 4 is on\n");
}
else
{
  printf("Port D pin 4 is off\n");
}

Now I'm not sure what the problem is, but its just not working.  It will never read anything besides "Port D pin 4 is on".  I have a button that pulls the pin low, and my multimeter confirms that when I press the button the pin really does go from close to 5V to around 0.02V.  I set the internal pull-up resistors on port D  I have been able to successfully connect the button to an analog pin and use a2dConvert8bit() to tell me whether the button is pressed or not.  If I output the result of a2dConvert8bit() to uart, it shows 255 when the button is not pressed, and close to 0 when the button is pressed so I know the button is working fine and is successfully pulling the pin low.  The problem has to be in the code somewhere.  But I don't know if the problem is in setting the pins to input/output correctly, if I'm not reading the pin correctly, or if I'm just not getting the pin close enough to 0V to read as "low".  I don't know how sensitive that sort of thing is.  I imagined that anything below half of 5V would read as low and anything above half of 5V would read as high but I don't have any experience backing this up. 

Offline greasemonkey94

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
Re: Configuring Inputs & Outputs on $50 Bot
« Reply #1 on: December 28, 2010, 09:28:49 AM »
I'm not really sure what the problem is either
but when i converted 0x0f to binary i got 0b1111.
That looks like you have initialized only 4 pins? ???
I think it should be 0b00011111.

try this DDRD=0xF

Hope this helps
« Last Edit: December 28, 2010, 09:50:20 AM by greasemonkey94 »

Offline VegaObscuraTopic starter

  • Robot Overlord
  • ****
  • Posts: 153
  • Helpful? 6
Re: Configuring Inputs & Outputs on $50 Bot
« Reply #2 on: December 28, 2010, 01:43:48 PM »
Well 0xF and 0x0F both convert to the same thing.  Try it in google.  But the problem remains.  Even when I use DDRD = 0x00, it still reads pin 4 is on no matter what.

Offline greasemonkey94

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
Re: Configuring Inputs & Outputs on $50 Bot
« Reply #3 on: December 29, 2010, 09:24:21 AM »
Well 0xF and 0x0F both convert to the same thing.  Try it in google.  But the problem remains.  Even when I use DDRD = 0x00, it still reads pin 4 is on no matter what.

sorry about that :(, thought I was being smart hehe, just trying to help.

I hope you get this resolved soon though

EDIT- There may be a confusion of pins because pin 4 on atmega 168(and 8 ) is pin D2. are you sure the button is on the right pin?
         Do you want D4(pin 6) to be input or pin 4 on the atmega (D2) to be input??
« Last Edit: December 30, 2010, 02:42:46 AM by greasemonkey94 »

Offline greasemonkey94

  • Jr. Member
  • **
  • Posts: 29
  • Helpful? 1
Re: Configuring Inputs & Outputs on $50 Bot
« Reply #4 on: December 30, 2010, 07:17:45 AM »
I'm curious to know, was that the problem or not???

Offline VegaObscuraTopic starter

  • Robot Overlord
  • ****
  • Posts: 153
  • Helpful? 6
Re: Configuring Inputs & Outputs on $50 Bot
« Reply #5 on: December 30, 2010, 01:36:29 PM »
Sorry about the slow update.  I've been spending my bot time getting uart to work.  No, I double checked that I was using the correct pin many times, and checked the datasheet several times to make sure I hadn't confused anything.  I was aware that PORTD, 4 is actually pin 6.  Keep the possible solutions coming though!

 


Get Your Ad Here