Write file to PC

10 Jun 2011

Hello,

Is there a way to open and write a file directly to the connected computer through the USB port. The file is a continuous data logging file so its size can get really big (no local file).

printf() to screen could probably work then copy paste into file, but it wouldn't be a too professional approach.

Thanks Levente

10 Jun 2011

If you're using Terra Term Pro in windows, you can use the logging option under the file menu. Alternatively, you can open a command prompt and type:

ttermpro /C=X /BAUD=9600 /L=log.txt

Where X is the com port number, /BAUD=9600 is the Baud rate of the serial link, and log.txt is the output log file. You must be in the Terra Term folder(i.e. c:\Program Files\terraterm\) to run ttermpro.exe

If you like a pure command line tool, see SerialTerm: http://www.comp.lancs.ac.uk/~albrecht/sw/terminal/index.html

I hope that helps!

10 Jun 2011

Thanks but i am using mac. Any alternative for Mac OSx you are aware of?

10 Jun 2011

Hi,

I was looking for a similar thing a few weeks ago. I wanted to create and open a file on my PC using the mbed and fill it with data. Couldn't figure a quick way of doing it so I ended up writing the data to a memory stick using Igor's USB Host

If you find a better way of doing it please share it with us!

10 Jun 2011

Ok, for OSX you can use screen:

The -L option outputs a session log file

screen -L /dev/<mbedttydevice>

where <mbedttydevice> is the mbed serial stream on your computer found in /dev/. To see a list of TTY streams you can do:

ls /dev/tty.*

You can also invoke screen and do Ctrl-A :H to start logging the session to a file.

10 Jun 2011

So if i understand it well first u get the screen to display all printf() lines in the format set in mbed code then using CTRL+A then H will create a log file saving all these lines?

That sounds something might work! Thanks for your research! Now I just hope using this method will create a file what I will be able to read at the end.

10 Jun 2011

MacOSX is UNIX, so it is simple enough to direct the shell output to a file (Just follow Igor Martinovski advice) :)

10 Jun 2011

Matt, for some reason, the screen > log.txt didn't work...

Levente, the logging option of screen just dumps what you see on the terminal to a file, effectively writing the serial stream to a file..just remember the colon (: char) when you do ctrl + A

10 Jun 2011

Thanks both of you,

I am trying it just now will let you know how it goes!

10 Jun 2011

Ok thanks Igor I have semi-success!

i see my data running on the screen but i pressed already everything to get a file out. (ctrl+a then H......etc) Can not find any file! I know it should be something like screenlog.0 but nothing I have the feeling it doesn't record it.

I know it doesnt really belongs here but thought you might have some experience since google doesn't really seems to help my case.

10 Jun 2011

Ignore me!!!! Figured, had to READ your comments! Thanks a millions! Now just hoping it can handle the 800Hz data stream for 10+ minutes.

Levente

11 Jun 2011

I'm glad you got it to work!

11 Jun 2011

Just an update:

I had issue to screen the mbed occasionally saying "Resource Busy" "Sorry, could not find a PTY."

This can be solved following this: http://www.planet-rcs.de/article/mac_serial_port/

Levi

11 Jun 2011

Ok, screen is working I can write to file but s sample rate I receive is LOW!

I reduced my code only send raw data @ 800Hz:

#include "mbed.h"

Serial mac(USBTX, USBRX);
SPI spi(p11, p12, p13); // mosi, miso, sclk
DigitalOut ac(p15);
DigitalOut recLed(p14); 
DigitalOut myled1(LED1);
DigitalIn recPush(p9);
DigitalIn stopPush(p10);
DigitalIn int1(p16);        //WATERMARK

int main()
{

    recLed=0;
    char test=1;
    char rec=0;

    spi.format(8,3);
    spi.frequency(600000);      //SPI link's clock to 600kHz
    ac=1;
    wait_ms(0.01);            
         
    ac=0;                   //set standby mode
    spi.write(0x2d);
    spi.write(0x00);
    wait_ms(0.01);
    ac=1;
    wait_ms(0.01);
    
    ac=0;                   //set FIFO
    spi.write(0x38);        // 0x00 for bypass
    spi.write(0xa1);        //0x92 for STREAM mode size 18 samples  93 for 19     bf for full size 0xa1 to size 1 so WARTERMARK act as DATA_READY
    wait_ms(0.01);          //0xd2 for TRIGGER mode size 18 samples  d3 for 19
    ac=1;
    wait_ms(0.01);
       
    ac=0;                   //set interrupt WATERMARK to pin: INT1 and DATAREADY to pin: INT2 0xfd
    spi.write(0x2f);        //OVERRUN also to INT2
    spi.write(0xfd);       
    wait_ms(0.01);
    ac=1;
    wait_ms(0.01);
            
    ac=0;                   //set sample rate to:
    spi.write(0x2c);                    //           800 Hz   0d
    spi.write(0x0d);                    //          1.6 KHz   0e
    wait_ms(0.01);                      //          400 Hz    0c  
    ac=1;
    wait_ms(0.01);
   
    ac=0;                   //read device ID should be E5
    spi.write(0x80);        //first bit of address byte 0-write 1-read 
    char l = spi.write(0x00);
    wait_ms(0.01);
    ac=1;
    wait_ms(0.01);
            
            
    ac=0;                   //set SPI 4-wire, range 4g, full resolution and right-justified data
    spi.write(0x31);
    spi.write(0x0f);        //0x0d for left-justified 4g
    wait_ms(0.01);          //0x0f for left-justified 16g
    ac=1;
    wait_ms(0.01);
    
     ac=0;                   //set interrupt DATA_READY 0x80
    spi.write(0x2e);        //               WATERMARK 0x02
    spi.write(0x82);        // 0x82 for both       
    wait_ms(0.01);          //0x03 for enable WATERMARK and OVERRUN
    ac=1;
    wait_ms(0.01);
            
    ac=0;                   //set measurement mode
    spi.write(0x2d);
    spi.write(0x08);
    wait_ms(0.01);
    ac=1;
    
      mac.printf("ADXL345 test\n\r");
      mac.printf("Device ID: %X\n\r", l);
      mac.printf("g-values\n\r");
      mac.printf("\tx-axis  \ty-axis  \tz-axis  \n\n\r");
      
        
    while(test==1)
    { 
    
         if (recPush==1)  {
            rec=1; 
            myled1=1;
       }//if recPush end
       
        while(rec==1)
        {
            recLed=1;
            

         if(int1 == 1){         //if data is ready in FIFO

         wait_ms(0.1);
            ac=0;                       //fetch x,y,z-data
            spi.write(0xf2);            //setting address byte's second bit means multiple-byte read
          char x0 = spi.write(0x00);
          char x1 = spi.write(0x00);
          char y0 = spi.write(0x00);
          char y1 = spi.write(0x00);
          char z0 = spi.write(0x00);
          char z1 = spi.write(0x00);
          wait_ms(0.01);
            ac=1;
           
            if (stopPush==1)
                rec=0;

            mac.printf("%c\t%c\t%c\t%c\t%c\t%c\n\r", x1, x0, y1, y0, z1, z0);
           
           }         // int1/2 if statement end
      
            if (stopPush==1) {
                rec=0;
                //ac=1;
            }    
        }//while REC close
        recLed=0;
     }       //while test==1 end
}

Is printf() so slow or the transmission? I tried terminal and CoolTerm as well. Any suggestion?

11 Jun 2011

BAUDRATE!!!

Sorry need to sleep I guess. Just one last thing, any way to get rid of the extra blank row between my data lines?

(Like an extra \n)

14 Jun 2011

Never mind, screenlog doesn't needs the screen to display the \n to have it recorded in the file. Thanks again!