nk_smir
Posts: 13
Joined: Sun Jun 24, 2012 5:04 am

Raspberry Pi Robotic Board

Sat Jul 21, 2012 11:44 pm

AFLEX Robotic Board is available on http://www.web4robot.com

The board is dual motor control and data acquisition board with I2C and Serial interfaces.
The board provides 2 motor control drivers with max current up to 3.5A, 8-bits data port with each pin setup as digital input/output or analog input, 10-bits ADC with up to 5 analog channels, 4 inputs for the sensor connections, infrared (IR) remote control.
The board provides direct connection to Raspberry Pi.

greypower
Posts: 92
Joined: Sat Jan 07, 2012 10:00 am

Re: Raspberry Pi Robotic Board

Sun Jul 22, 2012 10:43 am

What is the price of this board please?
Also, perhaps you should enter this under "Ye Olde Pi Shoppe"/"Add-ons for sale" forum too.

nk_smir
Posts: 13
Joined: Sun Jun 24, 2012 5:04 am

Re: Raspberry Pi Robotic Board

Sun Jul 22, 2012 7:10 pm

"AFlex - 2" board price - $20.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Raspberry Pi Robotic Board

Mon Jul 30, 2012 11:18 pm

I bought the flexel board further down the page - it was also about $20 - needs a logic level converter though as works on 5v not 3.3v

nk_smir
Posts: 13
Joined: Sun Jun 24, 2012 5:04 am

Re: Raspberry Pi Robotic Board

Sat Aug 04, 2012 4:30 am

AFlex is new board. The module supports 5V and 3.3V systems and provides direct connection to Raspberry Pi. You don't need to use the voltage shifter.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi Robotic Board

Sat Aug 04, 2012 7:45 am

Your pdf shows pin 9 as ground. Isn't it pin 6 on the Raspberry?
http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29

Also the diagrams in the pdf http://www.web4robot.com/files/AFlex.pdf
show a seemingly random collection of P1 pins being connected to the AFlex pins SCL/SDA/GND/5V.

L200man
Posts: 4
Joined: Sat Dec 24, 2011 6:39 pm

Re: AFlex Raspberry Pi Robotic Board

Mon Oct 01, 2012 12:51 pm

OK I have the board, the Aflex connection/Users guide

Does anyone have any code for its use ?
Do you use Python for the programming ?

Sorry - I'm VERY new to this linux programming :D

Chris

dkindred
Posts: 2
Joined: Thu Jun 14, 2012 12:22 pm

Re: AFlex Raspberry Pi Robotic Board

Tue Apr 09, 2013 12:34 pm

Hi, Chris,

Were you ever able to get the thing working? I just got mine in the mail yesterday, but haven't soldered the connectors on yet. I was thinking about trying to control it through the serial connection rather than I2C, because it seems more understandable. I thought I'd use the PySerial library. What have you been able to do?

--David

oharebp
Posts: 2
Joined: Thu Apr 04, 2013 8:56 pm

Re: Raspberry Pi Robotic Board

Wed Apr 17, 2013 5:24 pm

Hi,
Got this board to function more or less through I2C interface but still not certain about
motor control or limiting the motor current. Anyone got any further with it!

nfortin
Posts: 1
Joined: Fri Apr 19, 2013 1:04 am

Re: Raspberry Pi Robotic Board

Fri Apr 19, 2013 1:10 am

I converted the A-Flex C sample to python. It works pretty well. Feel free to use it.

Note: Written for Python 3

-Nate

Code: Select all

#!/usr/bin/env python3
#//////////////////////////////////////////////////////
# "AFLEX" shield Library
#  AFLEX v0.1 
# Uses I2C Wires interface
# Uses Analog pin 4 - SDA
# Uses Analog pin 5 - SCL
#//////////////////////////////////////////////////////
# Declarations:
#//////////////////////////////////////////////////////
import time
from quick2wire.i2c import I2CMaster, writing_bytes, reading 

#////////////////// Module Control Commands ///////////////////////////////////////
#////////////////// Command List ///////////////////////////////////////
FIRMWARE_VER           = 0x24
READ_REMOTE_CTRL       = 0x35

PIN_MODE               = 0x40
DIGITAL_WRITE          = 0x41
DIGITAL_READ           = 0x42
ANALOG_READ            = 0x43
FREQ_READ              = 0x44

MOTOR_FORWARD          = 0x50
MOTOR_REVERSE          = 0x51
MOTOR_STOP             = 0x52
MOTOR_CURRENT          = 0x53
SWITCH_READ            = 0x54

PRT_STRING             = 0x10

#/// Constants  /////////////////////////
aflex_i2caddress       = 0x4A  # Default address of the board
ANALOG_MODE            = 0x05
FREQ_MODE              = 0x06

AFLEX_COMMAND          = 0xFE  # command start byte
AFLEX_CMDDELAY         = 0.01  # 100uS


#///////////////////////////////////////////////////////////////////////////////////
# Read the module firmware version 
#////////////////////////////////////////////////////////////////////////////////////
def firmware():
	with I2CMaster() as bus:
		number = 1
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,FIRMWARE_VER))
		time.sleep(AFLEX_CMDDELAY)
		raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
		print (FIRMWARE_VER," - ",raw_bytes[0])
	return raw_bytes[0]

#////////////////////////////////////////////////////////////////////////////////////
# Motor Forward command
#////////////////////////////////////////////////////////////////////////////////////
def motorForward(motor, pwm):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_FORWARD,motor,pwm))
		time.sleep(AFLEX_CMDDELAY)
	return 1

#////////////////////////////////////////////////////////////////////////////////////
# Motor Reverse command
#////////////////////////////////////////////////////////////////////////////////////
def motorReverse(motor, pwm):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_REVERSE,motor,pwm))
		time.sleep(AFLEX_CMDDELAY)
#////////////////////////////////////////////////////////////////////////////////////
# Motor Stop command
#////////////////////////////////////////////////////////////////////////////////////
def motorStop(motor):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_STOP,motor))
		time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# Set Max Motor Current command
#////////////////////////////////////////////////////////////////////////////////////
def motorCurrent(current):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_CURRENT,current))
		time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# Set pin mode (INPUT, OUTPUT, ANALOG_MODE, FREQ_MODE)
# pin in range 1...8
#////////////////////////////////////////////////////////////////////////////////////
def pinMode(pin, mode):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,PIN_MODE,pin,mode))
		time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# digital pin write
# pin in range 1...8
#////////////////////////////////////////////////////////////////////////////////////
def digitalWrite(pin, value):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,DIGITAL_WRITE,pin,value))
		time.sleep(AFLEX_CMDDELAY)
      
#////////////////////////////////////////////////////////////////////////////////////
# digital pin read
# pin in range 1...8
#////////////////////////////////////////////////////////////////////////////////////
def digitalRead(pin):
	with I2CMaster() as bus:
		data = 0x00
		number = 1
  
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,DIGITAL_READ,pin))
		time.sleep(AFLEX_CMDDELAY)
		raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
	return raw_bytes[0]
  
#//////////////////////////////////////////////////////////////////////////////////
# Analog channel read
# returns 10-bit ADC value for the selected pin
#////////////////////////////////////////////////////////////////////////////////////
def analogRead(pin):
	with I2CMaster() as bus:
		data = 0x00
		number = 2
		print(pin)
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,ANALOG_READ,pin))
		time.sleep(AFLEX_CMDDELAY)
		raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
		print(raw_bytes)
		data = (256*int(raw_bytes[0]) + int(raw_bytes[1]))
	return data;

#//////////////////////////////////////////////////////////////////////////////////
# Analog channel read
# returns 2 bytes frequency value for the selected pin
#////////////////////////////////////////////////////////////////////////////////////
def frequencyRead(pin):
	with I2CMaster() as bus:
		number = 2
		data = 0x00
  
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,FREQ_READ,pin))
		time.sleep(AFLEX_CMDDELAY)
		raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
		
		data = (256*int(raw_bytes[0]) + int(raw_bytes[1]))
	return data;

#///////////////////////////////////////////////////////////////////////////////////
# Read the switches (swittch 1 - Bit1,.. switch 4 - Bit4 
#////////////////////////////////////////////////////////////////////////////////////
def switchRead():
	with I2CMaster() as bus:
		data = 0x00;
		number = 1;
		
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,SWITCH_READ))
		time.sleep(AFLEX_CMDDELAY)
		raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
	return raw_bytes[0]

#///////////////////////////////////////////////////////////////////////////////////
# Read Remote Control command
# Read the Remote Control buffer and returns 1 received byte (0x00 if not data) 
#////////////////////////////////////////////////////////////////////////////////////
def remoteRead():
	with I2CMaster() as bus:
		data = 0x00;
		number = 1;
		
		bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,READ_REMOTE_CTRL))
		time.sleep(AFLEX_CMDDELAY)
		raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
	return raw_bytes[0]

  
#////////////////////////////////////////////////////////////////////////////////////
# write command
# Send a data byte to AFLEX board 
#////////////////////////////////////////////////////////////////////////////////////
def write(value):
	with I2CMaster() as bus:
		bus.transaction(writing_bytes(aflex_i2caddress,value))
		time.sleep(AFLEX_CMDDELAY)

print(firmware())
motorCurrent(250)

for x in range(0,250):
	motorForward(1,x)
	time.sleep(0.1)
	print(x)
motorStop(1)
motorStop(2)

for x in range(0,250):
	motorReverse(1,x)
	time.sleep(0.1)
	print(x)
motorStop(1)
motorStop(2)
	
motorStop(1)
motorStop(2)	


kkjensen
Posts: 8
Joined: Mon May 13, 2013 5:20 am

Re: Raspberry Pi Robotic Board

Mon May 13, 2013 5:40 am

Thanks for translating to python. Where does the quick2wire.i2c file come from? When I try running your example (tweaked slightly to only test 1 motor) it gives me an error that there is no module named quick2wire.i2c. EDIT: I found the tutorial I needed over at adafruit...they provided exactly what was needed to get the quick2wire going and everything else.

cheers! This looks like a pretty decent little expansion board for the money!

PS (I've got some lights blinking and stuff. Just can't get the motors to spin [yet]).

talasinski
Posts: 1
Joined: Wed Apr 17, 2013 4:17 pm
Location: Livermore, CA

Re: Raspberry Pi Robotic Board

Fri Dec 13, 2013 12:12 am

Do you have a copy of the c code?

Tom


[quote="nfortin"]I converted the A-Flex C sample to python. It works pretty well. Feel free to use it.

Note: Written for Python 3

-Nate

[code]
#!/usr/bin/env python3
#//////////////////////////////////////////////////////
# "AFLEX" shield Library
# AFLEX v0.1
# Uses I2C Wires interface
# Uses Analog pin 4 - SDA
# Uses Analog pin 5 - SCL
#//////////////////////////////////////////////////////
# Declarations:
#//////////////////////////////////////////////////////
import time
from quick2wire.i2c import I2CMaster, writing_bytes, reading

#////////////////// Module Control Commands ///////////////////////////////////////
#////////////////// Command List ///////////////////////////////////////
FIRMWARE_VER = 0x24
READ_REMOTE_CTRL = 0x35

PIN_MODE = 0x40
DIGITAL_WRITE = 0x41
DIGITAL_READ = 0x42
ANALOG_READ = 0x43
FREQ_READ = 0x44

MOTOR_FORWARD = 0x50
MOTOR_REVERSE = 0x51
MOTOR_STOP = 0x52
MOTOR_CURRENT = 0x53
SWITCH_READ = 0x54

PRT_STRING = 0x10

#/// Constants /////////////////////////
aflex_i2caddress = 0x4A # Default address of the board
ANALOG_MODE = 0x05
FREQ_MODE = 0x06

AFLEX_COMMAND = 0xFE # command start byte
AFLEX_CMDDELAY = 0.01 # 100uS


#///////////////////////////////////////////////////////////////////////////////////
# Read the module firmware version
#////////////////////////////////////////////////////////////////////////////////////
def firmware():
with I2CMaster() as bus:
number = 1
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,FIRMWARE_VER))
time.sleep(AFLEX_CMDDELAY)
raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
print (FIRMWARE_VER," - ",raw_bytes[0])
return raw_bytes[0]

#////////////////////////////////////////////////////////////////////////////////////
# Motor Forward command
#////////////////////////////////////////////////////////////////////////////////////
def motorForward(motor, pwm):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_FORWARD,motor,pwm))
time.sleep(AFLEX_CMDDELAY)
return 1

#////////////////////////////////////////////////////////////////////////////////////
# Motor Reverse command
#////////////////////////////////////////////////////////////////////////////////////
def motorReverse(motor, pwm):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_REVERSE,motor,pwm))
time.sleep(AFLEX_CMDDELAY)
#////////////////////////////////////////////////////////////////////////////////////
# Motor Stop command
#////////////////////////////////////////////////////////////////////////////////////
def motorStop(motor):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_STOP,motor))
time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# Set Max Motor Current command
#////////////////////////////////////////////////////////////////////////////////////
def motorCurrent(current):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,MOTOR_CURRENT,current))
time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# Set pin mode (INPUT, OUTPUT, ANALOG_MODE, FREQ_MODE)
# pin in range 1...8
#////////////////////////////////////////////////////////////////////////////////////
def pinMode(pin, mode):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,PIN_MODE,pin,mode))
time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# digital pin write
# pin in range 1...8
#////////////////////////////////////////////////////////////////////////////////////
def digitalWrite(pin, value):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,DIGITAL_WRITE,pin,value))
time.sleep(AFLEX_CMDDELAY)

#////////////////////////////////////////////////////////////////////////////////////
# digital pin read
# pin in range 1...8
#////////////////////////////////////////////////////////////////////////////////////
def digitalRead(pin):
with I2CMaster() as bus:
data = 0x00
number = 1

bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,DIGITAL_READ,pin))
time.sleep(AFLEX_CMDDELAY)
raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
return raw_bytes[0]

#//////////////////////////////////////////////////////////////////////////////////
# Analog channel read
# returns 10-bit ADC value for the selected pin
#////////////////////////////////////////////////////////////////////////////////////
def analogRead(pin):
with I2CMaster() as bus:
data = 0x00
number = 2
print(pin)
bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,ANALOG_READ,pin))
time.sleep(AFLEX_CMDDELAY)
raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
print(raw_bytes)
data = (256*int(raw_bytes[0]) + int(raw_bytes[1]))
return data;

#//////////////////////////////////////////////////////////////////////////////////
# Analog channel read
# returns 2 bytes frequency value for the selected pin
#////////////////////////////////////////////////////////////////////////////////////
def frequencyRead(pin):
with I2CMaster() as bus:
number = 2
data = 0x00

bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,FREQ_READ,pin))
time.sleep(AFLEX_CMDDELAY)
raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]

data = (256*int(raw_bytes[0]) + int(raw_bytes[1]))
return data;

#///////////////////////////////////////////////////////////////////////////////////
# Read the switches (swittch 1 - Bit1,.. switch 4 - Bit4
#////////////////////////////////////////////////////////////////////////////////////
def switchRead():
with I2CMaster() as bus:
data = 0x00;
number = 1;

bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,SWITCH_READ))
time.sleep(AFLEX_CMDDELAY)
raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
return raw_bytes[0]

#///////////////////////////////////////////////////////////////////////////////////
# Read Remote Control command
# Read the Remote Control buffer and returns 1 received byte (0x00 if not data)
#////////////////////////////////////////////////////////////////////////////////////
def remoteRead():
with I2CMaster() as bus:
data = 0x00;
number = 1;

bus.transaction(writing_bytes(aflex_i2caddress,AFLEX_COMMAND,READ_REMOTE_CTRL))
time.sleep(AFLEX_CMDDELAY)
raw_bytes = bus.transaction(reading(aflex_i2caddress,number))[0]
return raw_bytes[0]


#////////////////////////////////////////////////////////////////////////////////////
# write command
# Send a data byte to AFLEX board
#////////////////////////////////////////////////////////////////////////////////////
def write(value):
with I2CMaster() as bus:
bus.transaction(writing_bytes(aflex_i2caddress,value))
time.sleep(AFLEX_CMDDELAY)

print(firmware())
motorCurrent(250)

for x in range(0,250):
motorForward(1,x)
time.sleep(0.1)
print(x)
motorStop(1)
motorStop(2)

for x in range(0,250):
motorReverse(1,x)
time.sleep(0.1)
print(x)
motorStop(1)
motorStop(2)

motorStop(1)
motorStop(2)

[/code][/quote]

Return to “Interfacing (DSI, CSI, I2C, etc.)”