11 years, 8 months ago.

sending commands via usb to mbed to control PWM or analog out

Hi,

anyone have a simple program that accepts simple string commands via usb that i can parse to control PWM or DAC output?

rgds,

5 Answers

11 years, 8 months ago.

Hi,

Try looking at the RPC over serial features - they may be a good starting point!

HTH

Jez

Dave Tung
poster
11 years, 8 months ago.

Jez,

thanks for the suggestion. I'll take a look and see how the RPC goes. Is there anything in the mBed classes that might also work?

dmt

11 years, 8 months ago.

You can also just use a serial object via the USB port, and then write some code to decode the message and set the PWM/DAC accordingly.

11 years, 8 months ago.

The simpelest is ..

PwmOut myled(LED1);
PwmOut myled2(LED2);
serial pc (USBTX,USBRX);

int main() 
{
    while(1) 
    {
      if(pc.readble()))
      {
        float brightness, brightness2;
        scanf("%f,%f", &brightness,&brightness2);
        myled = brightness;
        myled2 = brightness2;
      }
   }
}

then from pc, send two commer seperated values (or however mainy)

followed by CR.

This can be done from Lab View, Delphi, or just boring typing.

Enjoy

Ceri

Ceri, Erik and Jez,

thanks for the suggestion. It looks like this would work. I'm actually interfacing from python. I also found an pc_rpc.py to try out Jez's ideas. I'll let you guys know which one was easiest for me to implement. If I have any question I'll be sure to ask the you guys for suggestions. Thanks again.

dave

posted by Dave Tung 28 Feb 2013
9 years, 12 months ago.

thx