Connect to Raspberry Pi USB port/hub, user will be able to access up to 8 Digitally Isolated Input and 8 Digitally Isolated Output. Good for machine control, home automation, etc. Come with din-reel plastic case and one set of USB cable. Easy plug in, without risk to the Raspberry Pi.
On board LED indication.
Program thru simple string sent thru the virtual Serial Port.
Email: chin.ghee.tan@tcosystem.com for details and pricing.
USB Serial - 8 Input/Output Board for Raspberry Pi
13 posts
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
Out of curiosity, has this been tested with an actual Raspberry Pi or it using a common usb protocol such that compatibility is practically ensured?
Dear forum: Play nice 
It was tested with actual Raspberry Pi, I just receive my unit last week. I will try to post more details on this. It is using standard CDC to emulate the Serial Port on Linux, you will be accessing the device as opening a device. This is the sample code i tested recently, to write and read back from the device.
- Code: Select all
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
/*
* 'open_port()' - Open serial port 1.
*
* Returns the file descriptor on success or -1 on error.
*/
int
open_port(void)
{
int fd; /* File descriptor for the port */
fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyACM0 - ");
}
else
{
printf("Ok");
//fcntl(fd, F_SETFL, 0);
fcntl(fd, F_SETFL, FNDELAY);
}
return (fd);
}
main()
{
int fd;
int n;
char buffer[7]; /* Input buffer */
char *bufptr; /* Current char in buffer */
int nbytes; /* Number of bytes read */
int tries; /* Number of tries so far */
struct termios options;
fd = open_port();
/*
* Get the current options for the port...
*/
tcgetattr(fd, &options);
/*
* Set the baud rates to 19200...
*/
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
/*
* Enable the receiver and set local mode...
*/
// options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
/*
* Set the new options for the port...
*/
options.c_cflag |= (CLOCAL | CREAD);
options.c_cc[VMIN] = 0; //min carachters to be read
options.c_cc[VTIME] = 0; //Time to wait for data (tenths of seconds)
tcsetattr(fd, TCSANOW, &options);
n = write(fd, "I0F", 3);
if (n < 0)
fputs("write() of 3 bytes failed!\n", stderr);
sleep(1);
n = write(fd, "IF0", 3);
if (n < 0)
fputs("write() of 3 bytes failed!\n", stderr);
sleep(1);
n = write(fd, "IFF", 3);
if (n < 0)
fputs("write() of 3 bytes failed!\n", stderr);
sleep(1);
n = write(fd, "IF0", 3);
if (n < 0)
fputs("write() of 3 bytes failed!\n", stderr);
sleep(1);
n = write(fd, "IFF", 3);
if (n < 0)
fputs("write() of 3 bytes failed!\n", stderr);
sleep(1);
n = read(fd, buffer, sizeof(buffer));
if (n < 0)
{
fputs("read failed!\n", stderr);
printf("n = %d\n",n);
}
else
printf("Successfully read from serial port -- %s\n", buffer);
close(fd);
}
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
Cool! Thanks for the additional info
Dear forum: Play nice 
Access to the USB Serial - 8 Input/Output Board using Python.
- Code: Select all
import serial
from time import sleep
# Connect to the USB Serial Port
port = "/dev/ttyACM0"
# Open the USB Serial Port
ser = serial.Serial(port, 115200)
# Write I00, this will off all 8 Output
x= ser.write('I00')
#read back the 7 bytes of reply from USB Serial, status of 8 input
data = ser.read(7)
print data
ser.close()
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
With Video Link
New code with GUI and a timer to set the output and read the input and update to the GUI.
Connect the input0 to a SUNX sensor, output7 to a relay to control a rotating light.
If input0 is triggered, output7 will On the relay which control the rotating light.
Below are the video link, it is still processing, will be done in two hours
http://www.youtube.com/watch?v=eUj5Mkdw4E0&feature=youtu.be
I am using timer since I am very new to python, proper one should be using threading.
New code with GUI and a timer to set the output and read the input and update to the GUI.
Connect the input0 to a SUNX sensor, output7 to a relay to control a rotating light.
If input0 is triggered, output7 will On the relay which control the rotating light.
Below are the video link, it is still processing, will be done in two hours
http://www.youtube.com/watch?v=eUj5Mkdw4E0&feature=youtu.be
I am using timer since I am very new to python, proper one should be using threading.
- Code: Select all
import wx
import time
import serial
from time import sleep
inloop = 0
x = 0
outputallvalue = 0 # all off initially
output0 = 0
output1 = 0
output2 = 0
output3 = 0
output4 = 0
output5 = 0
output6 = 0
output7 = 0
outputallstr = "I00"
# Open the port first for faster operation, no need to open close
# really new to this python
ser = serial.Serial("/dev/ttyACM0", 115200)
ser.timeout = 0
def CombineOutput():
global outputallvalue
global output0
global output1
global outputallstr
lowerbitvalue = output0+ 2*output1 +4* output2+8*output3
upperbitvalue = output4 + 2*output5 + 4*output6 +8*output7
print "All value "
print outputallvalue
#outputvallvalue = 15
#print outputvallvalue.hex
#print int("FF",16)
lowerbit = lowerbitvalue & 0xF
upperbit = upperbitvalue & 0xF
lowerbitstr = hex(lowerbit)
tempstr = lowerbitstr.upper()
print tempstr[-1:]
upperbitstr = hex(upperbit)
tempstr2 = upperbitstr.upper()
print tempstr2[-1:]
outputallstr = 'I' + tempstr2[-1:] + tempstr[-1:]
print outputallstr
#mydata = USBIO("/dev/ttyACM0",outputallstr)
def USBIO(devname, outputvalue):
# Connect to the USB Serial Port
global ser
global inloop
inloop = 1
port = devname
# Open the USB Serial Port
# Write I00, this will off all 8 Output
x= ser.write(outputvalue)
#read back the 7 bytes of reply from USB Serial, status of 8 input
data = ser.read(7)
print data
#ser.close()
inloop = 0
return data
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Timer Tutorial 1",
size=(500,500))
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.toggleBtn = wx.Button(panel, wx.ID_ANY, "Scan IO")
self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle)
#output
self.chkOutput = wx.CheckBox(panel,wx.ID_ANY, "Output 0",(20,45))
self.chkOutput.Bind(wx.EVT_CHECKBOX, self.onOutput0)
self.chkOutput1 = wx.CheckBox(panel,wx.ID_ANY, "Output 1",(20,75))
self.chkOutput1.Bind(wx.EVT_CHECKBOX, self.onOutput1)
self.chkOutput2 = wx.CheckBox(panel,wx.ID_ANY, "Output 2",(20,105))
self.chkOutput2.Bind(wx.EVT_CHECKBOX, self.onOutput2)
self.chkOutput3 = wx.CheckBox(panel,wx.ID_ANY, "Output 3",(20,135))
self.chkOutput3.Bind(wx.EVT_CHECKBOX, self.onOutput3)
self.chkOutput4 = wx.CheckBox(panel,wx.ID_ANY, "Output 4",(20,165))
self.chkOutput4.Bind(wx.EVT_CHECKBOX, self.onOutput4)
self.chkOutput5 = wx.CheckBox(panel,wx.ID_ANY, "Output 5",(20,195))
self.chkOutput5.Bind(wx.EVT_CHECKBOX, self.onOutput5)
self.chkOutput6 = wx.CheckBox(panel,wx.ID_ANY, "Output 6",(20,225))
self.chkOutput6.Bind(wx.EVT_CHECKBOX, self.onOutput6)
self.chkOutput7 = wx.CheckBox(panel,wx.ID_ANY, "Output 7",(20,255))
self.chkOutput7.Bind(wx.EVT_CHECKBOX, self.onOutput7)
#input
self.chkInput0 = wx.CheckBox(panel,wx.ID_ANY, "Input 0",(120,45))
self.chkInput1 = wx.CheckBox(panel,wx.ID_ANY, "Input 1",(120,75))
self.chkInput2 = wx.CheckBox(panel,wx.ID_ANY, "Input 2",(120,105))
self.chkInput3 = wx.CheckBox(panel,wx.ID_ANY, "Input 3",(120,135))
self.chkInput4 = wx.CheckBox(panel,wx.ID_ANY, "Input 4",(120,165))
self.chkInput5 = wx.CheckBox(panel,wx.ID_ANY, "Input 5",(120,195))
self.chkInput6 = wx.CheckBox(panel,wx.ID_ANY, "Input 6",(120,225))
self.chkInput7 = wx.CheckBox(panel,wx.ID_ANY, "Input 7",(120,255))
#C1= wx.CheckBox(self, 1, 'Output 0', (20, 45))
#mydata = USBIO("/dev/ttyACM0",'I00')
def onOutput0(self, event):
global output0
if event.IsChecked():
print "\nOutput 0 Checked"
output0 =1
else:
print "\nOutput 0 UnChecked"
output0 = 0
CombineOutput()
def onOutput1(self, event):
global output1
if event.IsChecked():
print "\nOutput 1 Checked"
output1 = 1
else:
print "\nOutput 1 UnChecked"
output1 = 0
CombineOutput()
def onOutput2(self, event):
global output2
if event.IsChecked():
print "\nOutput 2 Checked"
output2 = 1
else:
print "\nOutput 2 UnChecked"
output2 = 0
CombineOutput()
def onOutput3(self, event):
global output3
if event.IsChecked():
print "\nOutput 3 Checked"
output3 = 1
else:
print "\nOutput 3 UnChecked"
output3 = 0
CombineOutput()
def onOutput4(self, event):
global output4
if event.IsChecked():
print "\nOutput 4 Checked"
output4 = 1
else:
print "\nOutput 4 UnChecked"
output4 = 0
CombineOutput()
def onOutput5(self, event):
global output5
if event.IsChecked():
print "\nOutput 5 Checked"
output5 = 1
else:
print "\nOutput 5 UnChecked"
output5 = 0
CombineOutput()
def onOutput6(self, event):
global output6
if event.IsChecked():
print "\nOutput 6 Checked"
output6 = 1
else:
print "\nOutput 6 UnChecked"
output6 = 0
CombineOutput()
def onOutput7(self, event):
global output7
if event.IsChecked():
print "\nOutput 7 Checked"
output7 = 1
else:
print "\nOutput 7 UnChecked"
output7 = 0
CombineOutput()
def onToggle(self, event):
global x
x = 0
btnLabel = self.toggleBtn.GetLabel()
if btnLabel == "Scan IO":
print "starting timer..."
self.timer.Start(40)
self.toggleBtn.SetLabel("Stop Scan")
else:
print "timer stopped!"
self.timer.Stop()
self.toggleBtn.SetLabel("Scan IO")
def update(self, event):
global x
global outputallvalue
global output0
global output1
global output7
print "\nupdated: ",
print time.ctime()
x = x +1
print x
if inloop == 0:
mydata = USBIO("/dev/ttyACM0",outputallstr)
# process the data return from the read
#IFFXX*
# Get the last three XX*
tempstr = mydata[-3:]
tempstr2 = tempstr[:2]
first4bit = tempstr2[:1]
second4bit = tempstr2[-1:]
upperbit = int(first4bit,16)
lowerbit = int(second4bit,16)
bit0 = lowerbit & 0x1
bit1 = (lowerbit & 0x2) >> 1
bit2 = (lowerbit & 0x4) >> 2
bit3 = (lowerbit & 0x8) >> 3
bit4 = upperbit & 0x1
bit5 = (upperbit & 0x2) >> 1
bit6 = (upperbit & 0x4) >> 2
bit7 = (upperbit & 0x8) >> 3
if bit0 == 0:
self.chkInput0.SetValue(True)
#on the relay to on rotating light
output7=1
CombineOutput()
self.chkOutput7.SetValue(True)
else:
self.chkInput0.SetValue(False)
output7=0
CombineOutput()
self.chkOutput7.SetValue(False)
if bit1 == 0:
self.chkInput1.SetValue(True)
else:
self.chkInput1.SetValue(False)
if bit2 == 0:
self.chkInput2.SetValue(True)
else:
self.chkInput2.SetValue(False)
if bit3 == 0:
self.chkInput3.SetValue(True)
else:
self.chkInput3.SetValue(False)
if bit4 == 0:
self.chkInput4.SetValue(True)
else:
self.chkInput4.SetValue(False)
if bit5 == 0:
self.chkInput5.SetValue(True)
else:
self.chkInput5.SetValue(False)
if bit6 == 0:
self.chkInput6.SetValue(True)
else:
self.chkInput6.SetValue(False)
if bit7 == 0:
self.chkInput7.SetValue(True)
else:
self.chkInput7.SetValue(False)
#outputallvalue = output0+ 2*output1
#print outputallvalue
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
ser.close()
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
Finally it is live in youtube now. I will post the technical details of this board soon.
http://www.youtube.com/watch?v=eUj5Mkdw4E0&feature=youtu.be
http://www.youtube.com/watch?v=eUj5Mkdw4E0&feature=youtu.be
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
Input and Output Spec. Will post the command protocol next.
Contact us at: chin.ghee.tan@tcosystem.com
Contact us at: chin.ghee.tan@tcosystem.com
- Attachments
-
- USB IO Spec.JPG (62.25 KiB) Viewed 6182 times
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
Connect USB Serial - 8 Input/Output Board to NPN Sensor, Sunx EX-14A
- Attachments
-
- Connection to Sensor.JPG (51.02 KiB) Viewed 6109 times
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am
While I appreciate the additional information on your board, please stop bumping your thread by dolling out the information so slowly 
Please either provide a link to the specs or have one last info dump post, but please don't keep posting information beyond that
Please either provide a link to the specs or have one last info dump post, but please don't keep posting information beyond that
Dear forum: Play nice 
abishur wrote:While I appreciate the additional information on your board, please stop bumping your thread by dolling out the information so slowly
Please either provide a link to the specs or have one last info dump post, but please don't keep posting information beyond that
Sorry, this will be the last one.
- Posts: 11
- Joined: Mon Jun 11, 2012 1:57 am