Community
cancel
Showing results for 
Search instead for 
Did you mean: 
KTech1
Novice
1,991 Views

calling mraa::Gpio "direction" effecting the output signal (Arduino Breakout)

Everytime I call mraa::Gpio "direction" method the output signal is not stable. Is this normal? I create the code to test. The code should give the steady rectangle pulse, however the actual output is distort.

# include

int main(void) {

mraa::Gpio *test;

test=new mraa::Gpio(7,true,false);

if (test==NULL) exit(mraa::ERROR_UNSPECIFIED);

if (test->dir(mraa::DIR_OUT)!=mraa::SUCCESS) exit(0);

test->mode(mraa::MODE_HIZ);

while(1) {

if (test->dir(mraa::DIR_OUT)!=mraa::SUCCESS) exit(0);

test->write(0);

if (test->dir(mraa::DIR_OUT)!=mraa::SUCCESS) exit(0);

test->write(1);

usleep(10000L);

}

}

0 Kudos
9 Replies
idata
Community Manager
65 Views

Hi KitTech,

Thank you for contacting us.

I tested your code and it worked fine. Take a look at the next photo:

Maybe the distortion it is just noise when you are measuring the data, I also noticed that you always use if (test->dir(mraa::DIR_OUT)!=mraa::SUCCESS) exit(0). It is not necessary, with the first declaration it is fine, take a look at this example: https://github.com/intel-iot-devkit/mraa/blob/master/examples/c%2B%2B/Blink-IO.cpp.

I hope you find this information helpful

Regards,

Leonardo R.

KTech1
Novice
65 Views

Dear LeonardoR,

Thank you for your response. Did you test it on the "Arduino Breakout Board"?

At first, I want to implement software I2C on the "Arduino Breakout board" and find this issue. So I trim the code for demonstration.

I intentionally put "if (test->dir(mraa::DIR_OUT)!=mraa::SUCCESS) exit(0)". It is the cause of the glitch. I think it is the effect of the level shifter on the board.

Regards,

Kittiphan T.

idata
Community Manager
65 Views

Hi Kittiphan T,

 

 

Yes, I tested it on the Arduino Breakout Board.

 

 

And this is weird, so yes it can be the level shifter, can you try test the code on another pin?

 

 

Let me know if you still have issues.

 

 

Regards,

 

Leonardo R.
idata
Community Manager
65 Views

Hi Kittiphan T,

 

 

Do you have any updates about this?

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
KTech1
Novice
65 Views

Dear Leonardo R.,

Thank you for following up. I kind of giving up on implementing the software I2C in the arduino breakout board.

It happens only when we call the command to change the GPIO direction.

If it is not happen to you, then it might be my board is defected. Will try again and let you know when i have a chance to test the other board.

Regards,

Kittiphan T.

idata
Community Manager
65 Views

Hi Kittiphan T,

 

 

Thank you for letting us know, but did you try it on another pin? And, yes please test it on another board and let us know.

 

 

We will be waiting for your reply.

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
KTech1
Novice
65 Views

Dear Leonardo R.,

I am sorry that I forget to mention that I add external pull-up resistor to the pin. Without the pull-up resistor the effect will not be seen.

FYI, I have tested on pin# 8 and # 13, the same thing happens. If I understand correctly, when the I/O changes the direction, some commands send to the level shifter. The effect seems to be the transient during that period.

 

Regards,

Kittiphan T.

idata
Community Manager
65 Views

Hi Kittiphan T,

 

 

Thank you for letting us know that you are using a pull-up. Can you tell us why are you using an external pull-up? We just want to know to help you more. As a reminder, the Arduino Breakout board has internal pull-ups, did you try to use them?

 

 

Have a nice day.

 

 

Regards,

 

Leonardo R.
KTech1
Novice
65 Views

Dear Leonardo R.,

The pull-up resistor is 1.8kOhm.

I am not using this technique anymore, but I've just tried to understand what is the cause of the issue.

Regards,

Kittiphan Techakittiroj

Reply