11 Replies Latest reply on Aug 2, 2014 6:56 AM by ghanashyamprabhu

    FastGpioRead - Examples


      Are there examples of FastGpioReads available on the community either in private/public versions? I need to decode a stream of input at around 1/600us (IR decoded stream)

      I tried a write up of the code by glancing through the fast_gpio_sc.h/c, variant.h/c and wiring_digital.h/c libraries. But looks like the function isn't returning the expected value. On a no IR activity, it should have returned no change in the input but the code shows up some noisy activity.


      It would help if some one can help review the code.




        • 1. Re: FastGpioRead - Examples

          Hi ghanashyamprabhu  


          I've checked your code but it seems the pin not switching back to LOW, it is set to 5V all the time. I think you need to toggle the pin, like in the example 2 of this post https://communities.intel.com/message/207904#207904. He is switching the pin to HIGH and LOW in line 9 where it says “x =!x;”, maybe you can implement something similar in your code. I hope you find this useful.



          • 2. Re: FastGpioRead - Examples

            I do not want to modify the output with x=!x and sending out x to the pin. The example seems to be for an OUTPUT drive. I would need an input.

            I have an LED connected to the ground at the output of the Arduino Pin2 but I see that the LED glows always which suggests there is a PULL Up on the output pin, Should I explicitly write to GPIO1 bit to get rid of the pull up?     

            • 3. Re: FastGpioRead - Examples

              I don see anything wrong in your use of fastGpioDigitalRead().
              It is the same as I have implemented in pulseIn() 


              Can you explain a little more on what you are trying to do?

              What does pin0 do? does it trigger a reading to be seen on pin3?

              Do you have a schematic or block diagram of what you are trying to do?


              Also can you show a console output you get from that while loop?
              I assume it is suppose to continuously loop until the 8th bit is a HIGH?

              • 4. Re: FastGpioRead - Examples



                Here's the circuit - I have an TSOP1740 which can decode an IR stream from a TV remote.

                I have the supply to the TSOP via a voltage divider to supply around 6v. I have the output of

                the decoder connected to the Pin2 of the Galileo board on which I intend to read the stream

                of data. If there is no IR activity from the remote control, the IR decoder would simply send

                out 0s or 1s (depending on polarity). When there is a button press on the remote, the IR

                decode would decode the modulated stream of data (38KHz) and send out pulses (1 or 0)

                separated by around 600us.


                So my loop would be something like


                loop {

                     read_value = Read input signal via Fast IO read;

                     If ( read value  != last_read_value ) {

                          // for the sake of decoding the value read the next stream of inputs

                          // for quite some time and print it out to check visually

                          loop {

                               // around 20 times

                               read_value = Read input via Fast IO read;

                               print Read_value

                               Insert delay of around 400 to 600us


                          last_read_value = read input signal via Fast IO read;





                And of course the board in diagram is a Galileo and not an Arduino. Fritzing doesn't support Galileo yet eh.    

                Galileo on Fritzing!! http://fritzing.org/download/0.9.0b/

                • 5. Re: FastGpioRead - Examples

                  The code example you had uses pin3. In your diagram pin3 is floating. That would explain all the noise you are reading.

                  Did you mean to use pin2 in your code as your input?

                  • 6. Re: FastGpioRead - Examples

                    I have tried both pin2 and pin3 (two Fast IOs on the Galileo) both show up the same behavior. I should probably the activity on an oscilloscope (I don't have one though and was expected to read directly it via Galileo). Another question on this fast IO read is about the pin read value - why does the fastGpioReadData(fastPin) return the value of the offset and not the value of the input?


                    I see you compare the fastGpioreadData with the targetValue and the targetValue is set to the offset 0x80 or 0x40 depending on which pin you read. Why is it comparing against the offset and not a value like 1 or 0 depending on the level of the input signal coming into the GPIO.


                    Also what about the internal pull ups on the GPIO - do those matter? I don't have anything specific in the code to get rid of the pull ups

                    • 7. Re: FastGpioRead - Examples

                      In pulseIn(), I am comparing it to the offset value since that is the value returned by fastGpioDigitalRead() when the value read is HIGH. It returns a 0 when the value is LOW

                      A wrapper around that function can easily be written so that it returns a 1 or 0.


                      I don think the pull-ups should make a difference if you have something connected to that pin that is always driving it HIGH or LOW.

                      Yeah, a scope would be really useful in this case.


                      Also I took a quick look a datasheet for a TSOP1740 and the middle pin is VS and the rightmost pin is OUT. Loking at your fritzing, this is not the case. Did you have a different version of the TSOP1740?

                      • 8. Re: FastGpioRead - Examples

                        Sorry about the Fritzing data - but the real circuit that I have on the breadboard also has an LED connected to the output of the TSOP which blinks when there is IR activity and show constant low light levels when there is no activity.    

                        • 9. Re: FastGpioRead - Examples

                          Hi, you can find the Fritzing schematic here:


                          ghanashyamprabhu wrote:


                          And of course the board in diagram is a Galileo and not an Arduino. Fritzing doesn't support Galileo yet eh.     




                          • 11. Re: FastGpioRead - Examples

                            Marking this as the correct answer - I cleaned up the circuit and removed unnecessary LEDs and resistors - Removed the 9V supply and used the one from Galileo - Also the TSOP seems to send out a 1 when its IDLE and had to change the logic a bit to detect start of the stream. Am still using fastIO and see some decent quality data being received.


                            Thanks so much for the support and quick responses.