Page 1 of 1
Formula AllCode Expansion ports
Posted: Tue Mar 14, 2023 4:44 pm
by Vic
I want to attach more IR sensors below the Formula Allcode Robot. However I am not sure to do so as I cannot get the expansion ports J16,J15 and J12 to work using the library provided using Python. How would I go on to fix this issues. Currently I cannot read or write to any of the ports.
import time
import FA
fa = FA.Create()
# make sure to use the correct COM port for your system
comport = 10
fa.ComOpen(comport)
# initialize the expansion port pin as an output
fa.ExpDDR(8, "OUTPUT") # I have tried just fa.ExpDDR(8) too
# turn on the LED on the expansion port
fa.ExpWrite(8, 1)
# wait for a second
time.sleep(1)
# turn off the LED on the expansion port
fa.ExpWrite(8, 0)
# close the communication link to the robot
fa.ComClose()
Re: Formula AllCode Expansion ports
Posted: Tue Mar 14, 2023 9:27 pm
by Benj
Hello,
I'm assuming your using the expansion numbering from here.
https://www.matrixtsl.com/resources/fil ... ansion.jpg
To set the pin to an output you probably need to call this.
ExpDDR(bitnumber,direction)
bitnumber would be 8 for IO pin 8 on the FA_Expansion image and direction would be 0 for an output and 1 for an input.
The writes you are doing look fine so hopefully it's just the second parameter for the ExpDDR function that was causing problems.
Re: Formula AllCode Expansion ports
Posted: Wed Mar 15, 2023 2:33 pm
by Vic
Hi Benj,
Thank for your reply. I have tested with directions 1 and 0.
I am not getting any voltage readings. The servomotor pins are working fine however none of the expansion ports give a reading.
this is the latest code i have used:
import time
import FA
class TestExpander:
def __init__(self):
self.robot = FA.Create()
#NOTE: make sure you use your actual COM port value here!
comport =4
self.robot.ComOpen(comport)
def test_output(self, pin):
# Set the pin as output
self.robot.ExpDDR(pin, 1)
# Write a high signal to the pin
self.robot.ExpWrite(pin, 1)
print(f"Pin {pin} is set as output and high signal is sent. Please check the voltage on the pin using a multimeter.")
time.sleep(5)
def test_input(self, pin):
# Set the pin as input
self.robot.ExpDDR(pin, 0)
# print(f"Pin {pin} is set as input. Please apply a voltage to the pin and press ENTER to continue.")
# input()
# Read the value on the pin
value = self.robot.ExpRead(pin)
print(f"Pin {pin} value: {value}")
# Read the analog value on the pin
analog_value = self.robot.ExpAn(pin)
print(f"Pin {pin} analog value: {analog_value}")
if __name__ == "__main__":
tester = TestExpander()
test_pin = 8
# Change this to the desired pin number
# Test output
tester.test_output(test_pin)
time.sleep(2)
# Test input
tester.test_input(test_pin)
CODE I ADJUSTED IN THE FA LIBRARY:
def ExpDDR(self, bitnumber, direction):
print("ExpDDR() called with bitnumber:", bitnumber, "and direction:", direction)
s = 'ExpDDR {0} {1}\n'.format(bitnumber, direction).strip()
self.__ser.write(s.encode())
# Read the response from the robot
response = self.__ser.readline().decode().strip()
print("Robot response:", response)
return
def ExpRead(self, bitnumber,timeout=100):
s = 'ExpRead {0}\n'.format(bitnumber)
self.__ser.write(s.encode())
r = self._readval("Bit", timeout)
return(r)
def ExpWrite(self, bitnumber, value):
s = 'ExpWrite {0} {1}\n'.format(bitnumber, value)
self.__ser.write(s.encode())
return
def ExpAn(self,annumber,timeout=100):
s = 'ExpAn {0}\n'.format(annumber)
self.__ser.write(s.encode())
r = self._readval("An", timeout)
return (r);
P.S when I apply voltage to the pin I either get no response or I get value: 1 no matter if im apply voltage or not. However with the E block pins when i apply voltage to light up the leds from D2 TO D8 but no reading can be capture from the code. I have tested this on 3 formula allcode robots.
Thanks,
Vic