Fedora Linux Support Community & Resources Center
  #1  
Old 11th March 2017, 03:58 PM
TablePC Offline
Registered User
 
Join Date: Jan 2013
Location: New York state in USA
Posts: 119
linuxfedorafirefox
Numato GPIO board

In the original thread on co-development of hardware and software, one topic briefly covered was the possibility of using the Numato General Purpose Input Output (GPIO) board as a means of connecting a PC to custom electronic circuitry. Numato makes 8, 16, 32, and 64 bit versions of the board. Each version has some pins that besides being used for digital I/O can be used to read analog levels converted by the board to binary values.

I am currently using the 8 bit version and thought I would show some "demo" code to operate the board. I am using Python and therefore this code is written in python. This requires the "pyserial" be installed and that the user is a member of Group "dialout". You can make yourself a member of dialout with:

PHP Code:
sudo adduser -G dialout username 
For more details reference the Numato manual at their web site: http://numato.com/8-channel-usb-gpio...analog-inputs/

Here is the python demo code for the Numato 8 bit GPIO board.

PHP Code:
# This program is not written as an example of good Python code Errors are not trapped
# etc. Instead it is quite minimal with the purpose of: Showing that Pyserial can be used
# to operate the Numato GPIO - 8 board. Get an idea of how fast the data to and from the
# board can be run. Experiment with ways to parse the data coming back from the board.
# This is not a characterization of the board or a test of the board. For this test each I/O
# pin of the board has an LED connected in series with a 1 K Ohm resistor connected to
# the board Ground. When a board output is at logic "1" the LED is on.

import serial

# This list contains a list of board commands that will be sent to the board in listed order.
# This is not a comprehensive list of possible board commands.

DigCommands = ['ver''id get''gpio writeall 00''gpio set 0''gpio clear 0''gpio set 1''gpio clear 1''gpio set 2',
               
'gpio clear 2''gpio set 3''gpio clear 3''gpio set 4''gpio clear 4''gpio set 5''gpio clear 5',
               
'gpio set 6''gpio clear 6''gpio set 7''gpio clear 7''gpio writeall ff''gpio readall''adc read 0',
               
'adc read 1''adc read 2''adc read 3''adc read 5''adc read 6''gpio writeall 00''gpio readall',
               
'adc read 0','adc read 1''adc read 2''adc read 3''adc read 5''adc read 6']

# This list will be the receiver for the string read form the board.

BytesIn = []

# Opens the serial connection to the board and checks for success.

Ser serial.Serial('/dev/ttyACM0')
              if 
Ser is None:
                   
raise ValueError('Numato 8 - Bit GPIO not found')

# Set the amount of time that Pyserial waits for the requested number of bytes to be
# received from the board. Strings from the board are not reliably read when the
# timeout value is below 0.005 seconds. This value can be increased to throttle
# the speed of sequencing through the commands by delaying completion of the
# reads. Read and write for that matter are independent of the set baudrate.
# This is to be expected as the board is a USB based Com port emulation.

Ser.timeout 0.010

# Wake up the board with an empty string.

Ser.write('')

# Print the characteristics of the serial port to sysout (the console window in the Eclipse IDE).

print Ser

# Determine the number of commands in the command list. Commands may be
# added to or deleted from the list above without modification to the code below.

RangeCom range(0, (len(DigCommands)))

# Sequence through the commands in listed order.

for NowCom in RangeCom:
    
    
# Get a command.
    
Command DigCommands[NowCom]
    
    
# Add a "CR" to the end of the command and send it to the board.
    
Ser.write(Command '\r')
    
    
# Read up to 64 bytes from the board. This is intentionally much larger than
    # a single string from the board will be. Read is Blocking, but the time
    # out above will allow the program to proceed though there will not be 64
    # bytes received
    
BytesIn Ser.read(64)
    
    
# Determine how long the string from the board is.
    
BytesInLen len(BytesIn)
    
    
# Prepare to check that the echoed command is equal to the sent command
    
comLength len(Command)
    
CheckCom BytesIn[0:comLength]
    
    
# Parse out just the returned data
    
Return = BytesIn[comLength:BytesInLen]
    
# Ignor the "LF CR >" characters at the end
    
ReturnLen len(Return)-3
    
    ReturnData 
= Return[2:ReturnLen]
    
    
# Send command and results to sysout (the console window in the Eclipse IDE).
    
print "Command Number: = "NowCom"  Command = "Command"  Sent = Echoed = ", (Command==CheckCom), "  Returned Data = "ReturnData
    
# Close the serial connection to the board.

Ser.close() 

Last edited by TablePC; 11th March 2017 at 04:42 PM.
Reply With Quote
Reply

Tags
board, gpio, numato

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
writing to /sys/class/gpio/export sharan013 Hardware & Laptops 0 9th February 2012 08:55 AM
Sound is working on A7K-A1, ALSA 1.0.19; you need to configure GPIO dfm7a Hardware & Laptops 6 29th April 2009 09:28 PM
how do i deal with General Register (GPIO) unikgila Programming & Packaging 1 31st August 2008 01:01 PM
How do I use GPIO with Winbond 83627THG? bill.whiteley Hardware & Laptops 3 2nd May 2007 07:33 PM
On board Display of Foxconn P4M800P7MA-RS2 mother board hosammy Hardware & Laptops 1 9th March 2007 07:38 PM


Current GMT-time: 01:33 (Tuesday, 30-05-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat