Starting Point System : Forum

You are not logged in.

#1 2010-07-22 03:30:57

New member

HELP : LInux commands

Hi y'all

I hope someone will read this -- with all the junk mails we have here ...

My device is recognized fine in Ubuntu (Linux).

I was able to do the normal commands -- ie..
echo "command" > /dev/ttyUSB0  ... like
echo "led on" > /dev/ttyUSB0
echo "pwm 9 on" ... etc...

What I want to know is how to read back...

say if I do a
echo "adc 1" > /dev/ttyUSB0

how do I get the data back?   I was doing
cat /dev/ttyUSB0
but it just hanged -- I have to do a "CTRL-C" to break out...

any ideas?


PS : Also I was able to find some code for OpenOffice (window) to write a command... but I can't seem to find the right combination to read...  Any hint?



#2 2010-07-22 20:27:25

New member

Re: HELP : LInux commands

Okie just to get more information out in case someone want to do this...

Now I hooked up the device according to
Where I made channel 9 into PWM and connect to the circuit similar to the link above.

I then input the "out" of the above circuit into channel 1 ... and used it to read back whatever voltage.

Here is the working code in "c"

#include <stdio.h>
#include <termios.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <string.h>
#include <errno.h>

static int fd = 0;
char devret[80],psdat[80];
char cmd[80];
int iIn = 0;
int erchk = 0;
char a1, a2;
char a[2];

int main(void) {

int lp1;

  fd = open("/dev/ttyUSB0", O_RDWR );

  a[0] = 10;   ///   LF and CR return...
  a[1] = 13;

  //  Turn on channel 9
  cmdWrite( "led on" );
  cmdWrite( "pwm 9 prescaler 4" );
  cmdWrite( "pwm 9 period 255" );
  cmdWrite( "pwm 9 width 0" );
  cmdWrite( "pwm 9 on" );

  for (lp1 = 0 ; lp1 < 256; lp1++) {
    // change the PWM width and write to device
    sprintf(cmd,"pwm 9 width %d",lp1);
    erchk = cmdWrite( cmd );
    if (erchk < 0) {
      fprintf(stderr,"Error in cmdWrite: %d\n",erchk);
      return 0;

    // check the output of channel 1
    erchk = cmdWrite("adc 1");
    if (erchk < 0) {
      fprintf(stderr,"Error in cmdWrite: %d\n",erchk);
      return 0;

    // printout the result
    // devret+5 gets rid of the "ADC 1" and returns just the result
    iIn = read(fd, devret, 16);
    printf("%d         %s\n", lp1,devret+5);

int cmdWrite(char cmdStr[])
int er1;

        er1 = write(fd, cmdStr, strlen(cmdStr));
        write(fd, a , 2);


Still trying to do that in OpenOffice (window)/Basic Script but having issue of reading back...
I will submit the "non-working" code in the next post....

Thanks & GL...



#3 2010-07-23 21:54:34

New member

Re: HELP : LInux commands

Hi Y'all...
Here is the code that doesn't work (OpenOffice Basic script)...
[I was able to write but not read]
it gives me "Basic runtime error"  at line "chk1 ="


Global oFSO as object

sub Test123

  Dim f123 as object
  Dim chk1 as string
    MsgBox "Running Test123..."
    oFSO  = createUnoService("").createInstance("Scripting.FileSystemObject")
        writedev("pwm 9 width 100")   '' already turn 9 on from other macro...
    writedev("adc 1")

    f123 = oFSO.OpenTextFile("COM4:9600,N,8,1", 1) 'for Reading
        chk1 =
end sub

function writedev(inputstr)
Dim f as object

Dim OutputChar as String

    f = oFSO.OpenTextFile("COM4:9600,N,8,1", 2) 'for Writing
    f.write(inputstr) 'Sending by each character

    OutputChar=Chr(10) 'LF
    OutputChar=Chr(13) 'CR
End Function



#4 2010-09-22 13:29:36

Laurent Aldon
New member

Re: HELP : LInux commands

I have tested my new ÁChameleon with a code written in Python running under Ubuntu 10.04 !
I works well...

You can have a look at
If you have any question,
feel you free
Please don't hesitate to contact me
Best regards,

Laurent Aldon

I am a teacher and I am trying to collect data from biopiles (microbial fuel cell) using Áchameleon !
I am coding in Python using Linux (Ubuntu)
Don't hesitate contact me to progress in developping tools...



Board footer

Powered by FluxBB