My name is Ted Burke (aka username batchloaf). I’m a lecturer in the School of Electrical and Electronic Engineering at the Dublin Institute of Technology (DIT Kevin Street) in Ireland. I teach a range of subjects including robotics, engineering computing, RoboSumo and biomedical engineering.

My primary research interests are signal processing (especially biomedical signals) and human-machine interfaces. I’m also interested in robotics, embedded systems, music technology and toys. I’m a founding member of the tPOT research group, which focuses on what we call ‘People Oriented Technology’ – technology that interacts well with humans.

This blog is really just a scrapbook for bits and pieces of code, notes, ideas, etc that crop up in my research and teaching. I created it for ad hocumentation.

Good Things

Loves: C, Python, PIC microcontrollers, Inkscape, BASH, Horowitz & Hill.
Likes: C++ , MATLAB / Octave, GIMP, gmail, Linux, LaTeX, OpenGL, MSP430 microcontrollers.
Useful things: awk, sed, grep, curl, wget, Notepad++, make, gcc, git, github, gnuplot, matplotlib, .svg, .csv, .pgm, ImageMagick, WordPress, PICkit 2, TI LaunchPad MSP430.
Bag of chips: dsPIC30f4011, PIC18F4620, MSP430Gxxxx, SN754410NE, L293D, LM358, AD627, pl2303hx.

75 Responses to About

  1. Richard says:

    That looks great. I’ll transfer my DSP blog or some of it to here.

    You are very anonymous on this BLOG, no name anywhere???

  2. Alex says:

    Hi, i was wandering if you could add to CommandCam the functionality to select the cam by knowing it’s name, something like “CommandCam.exe /devname ‘USB2.0Camera’ “. Best Regards, Alex

    • batchloaf says:

      Your wish is my command! I’ve just added that feature. See the updated CommandCam page for details.

      • Alex says:

        Thank you!! 😀

      • batchloaf says:

        You’re welcome. Let me know if you have any problems getting it to work for you. I was only able to try it out with one device name so far since I only have one camera here.

      • Jeff Marc says:

        I love commandcam, will willingly pay for camera brightness and contrast control feature added ! Hope u get this Jeff Marc USA

      • batchloaf says:

        Hi Jeff,

        Sorry, the new term has just begun so I’m flat out with teaching duties and working on CommandCam is not an option. To be honest though, I’m not sure if it would be possible adjust brightness and contrast at the image capture stage – I’m not sure if the DirectShow API provides a way of doing that. If it’s sufficient to adjust brightness and contrast after the image is already captured, then I would recommend ImageMagick, which is a free command line image processing program (actually a suite of programs). It’s very powerful and you can find a lot of examples online. Maybe you could use CommandCam to capture the image and then run an ImageMagick command to adjust brightness and contrast?

        Other possibilities include VLC and ffmpeg. Both are free to download and I think they would support image capture to a file from a camera device – maybe they would provide a way to control brightness / contrast of the captured image?


      • Jeff Marc says:

        Thanks for your reply! I know u are busy.
        researching this more, directx commands will support brightness control and other camera supported capabilities , much like TWAIN does wioth scanners. I believe it would be possible to write a camera utility that checks for and then supports all supoprted camera hardware functions, which are queuryable from the device.
        filtering after to adjust is not what i’m looking for when the device cleary supports them in other software, which also does not allow command line arguments for .

      • batchloaf says:

        Hi Jeff,

        Oh, that’s interesting to hear! It’s quite a while since I’ve added any new features to the DirectShow / DirectX parts of CommandCam, and I don’t use those APIs anywhere else any more, so I guess I’m a bit out of touch with what they provide. Now that you mention it though, it is kind of ringing a faint bell. Perhaps it was always there, but not many camera drivers used to support those features?

        Anyway, sorry I don’t have time to investigate incorporating this into CommandCam. It seems like it would be a very useful feature.

        One final note. I too did a little googling to see whether VLC might support what you need. It seems like it might. I just had a dig around in the GUI version and you can “Open capture device” in the File menu and there are advanced options for controlling all kinds of things during capture. As I understand it, pretty much anything you can do in the VLC GUI can be done with the command line version too, allowing you to script the video capture. It’s geared to video rather than still capture, but there’s probably a way to set it to capture just one frame. That’s basically what CommandCam does – it opens a video stream, captures one frame, then closes the stream. VLC is free, stable and well supported and includes a ton of useful features, so it might be worth considering.

        Best of luck!


      • Noe says:

        How can I get a hold of you?

      • batchloaf says:

        You can just leave a message here.


      • Noe says:

        this is powershell sending to comm port I was wondering if you knew the same thing in CMD?

        $robojax = New-Object System.IO.Ports.SerialPort COM5,9600,None,8,one
        $powerON = 0xA0,0x01,0x01,0xA2
        [Byte[]] $powerON = 0xA0,0x01,0x01,0xA2

      • batchloaf says:

        Hi Noe,

        I think you can do what you want using my SerialSend program:

        SerialSend.exe /devnum 5 /baudrate 9600 /hex “\xA0\x01\x01\xA2”

        You can download SerialSend from here:


        There’s probably a way to do it without installing anything at all, but I don’t know how exactly off the top of my head.


  3. lewisJang says:

    Hi. can I ask some questions ?

    I want use C++ system function to put my file to ftp .

    but, I type ftp command I will be a new shell.

    How can I use only one line command, put my file to ftp in ms-dos?

    • batchloaf says:

      Hi Lewis, if you type "ftp --help" in a DOS window you will see a list of additional options for the ftp command. One of these options ("ftp -s:filename") lets you specify a file that contains a list of commands to be run automatically by the ftp program. You can therefore create a file that contains the commands necessary to upload a file to your FTP server and save it in the same folder as your C++ program. Let’s imagine that you call this file "upload.txt". In your C++ program, your system command would then look something like the following:

          system("ftp -s:upload.txt my.ftphost.com");

      Obviously, you need to replace "my.ftphost.com" with whatever your FTP server is called.
      Unfortunately, I haven’t been able to try this for myself to check the exact details because I don’t have upload access to any FTP servers. If you have a problem getting it working, let me know.

  4. monica says:

    The device I’m using (Dual mode USB camera plus) supports two image sizes of 320×240 and 640×480. Is there anyway to select the larger image mode? Currently the device defaults to the smaller image. (When I use the “Select TWAIN device” from any photoeditor, I can change the size to the larger one)

    Also thanks for releasing this program to us, the public 🙂

    • batchloaf says:

      Hi Monica.

      Sorry for the delay in responding. I’m hoping to add this functionality to CommandCam in the next round of development. In the meantime, you could try my other program, RobotEyez which basically allows this. Here’s the link:


      RobotEyez is really just a program where I was trying out some different features that I plan to incorporate into CommandCam. To use RobotEyez this way, you would use a command like the following:

      RobotEyez /delay 1000 /width 640 /height 480 /bmp

      That should take a snapshot from the webcam after a 1 second delay, with the resolution set to 640×480, and save it to a file called “frame.bmp”.

      I hope that helps!

  5. Gayathri Devi KS says:

    I have to generate a PWM pulse from a carrier wave which is obtained by adding a triangular wave with a square pulse and this carrier wave should have a frequency of 1kHz frequency. The magnitude of carrier wave should be 2 at 0 seconds, 1 at 0.0005 seconds, 2 at 0.001 seconds and it reduces to -1 at the same moment that is at 0.001 seconds, -2 at 0.0015 seconds and -1 at 0.002 seconds and at the same instant it is increased to 2 and the same pattern repeats. Tthen this carrier is to be compared with a sinewave. Pleas help me to write a C program to generate a pulse. We have a micro controller PIC kit3 DSPIC4011. please help me.

  6. Gayathri Devi KS says:

    if you give me your mail id, Ican send the diagrams of the carrier waves and pulses which I want to generate so that it will be clear to you.

  7. Tom says:

    Hello, I have proposed you for Nobel prize, and I haven’t checked your code on Acer but I would like to make a small proposition, I’m very good in VBA but C++ and other C-s are total mistery for me. If you could help me to adjust code for taking pictures with preview and naming files with date of creation (and not deleting them) I would press that DONATE button so strong it would fall of screen :). Please say yes :). p.s. Sorry my english is not very good but I’m trying :).

  8. Tobias says:

    Hi Ted,
    I just want to thank you! Your CommandCam tool was a great help!
    If we ever meet, I’ll buy you a beer 😉

    Greetings from Germany,

  9. lopes says:

    Hi batchloaf. From what library are you using the commands _LATD0, _TRISD0, etc ? Thanks.

    • batchloaf says:

      Hi Lopes,

      For dsPIC programs, I use the XC16 compiler (previously called C30). With XC16, you just #include <xc.h> and it automatically pulls in the device specific header file for the specific chip you’re using (which it knows based on the compiler flags / MPLAB project settings). In the device specific header file (e.g. “p30f4011.h”) which is included automatically, the register names (LATD, TRISD, etc) are defined (hardlinked to specific memory addresses) and a number of C language bitfields are defined (LATDbits, TRISDbits, etc) which let you conveniently access individial bits within those registers. The ones you mentioned, such as “_LATD0” and “_TRISD”, are just macros defined as specific elements in the bitfields. For example,

      _LATD0 is just LATDbits.LATD0

      Hopefully, that explains it? If you have a dig through the header files in the compiler install directory, you’ll find the definitions there in the device specific header file for the chip you’re using.


  10. Luis Felipe says:

    Hi batchloaf,
    I live in Brazil and I’m writing to thank you for the informations that you post here. I never has worked with C on PICs but with your posts, I was able to do my final engineering graduate work last year.
    Thank, again.

  11. Firas Karam says:

    Hello Ted,
    i would like asking you if you have any idea how to send video through ethernet cables using usb webcam and pic Microcontroller ?

    • batchloaf says:

      Hi Firas,

      Do you mean that you want to create a device with a USB camera and PIC microcontroller (and no PC) which plugs straight into an ethernet socket and sends the video over the network?

      If so, I probably wouldn’t suggest using a PIC, or at least none of the PICs that I have used (PIC16F, PIC18F, dsPIC30F, etc). It’s likely that the PIC32 devices might be more appropriate for this type of application, but I haven’t used them so I can’t say for sure.

      If I was doing this myself, I’d probably start with a platform that has good support for hosting USB devices and connecting to Ethernet. For example, maybe you could use something like a Raspberry Pi or a higher end Arduino?

      With a Raspberry Pi, you would have Linux on board, so you could just pick a supported USB camera that’s already supported and then use an existing application like VLC or ffmpeg to stream the video over the network. You would just need to install whichever application you need and then plug in the camera and Ethernet cable. That’s the general approach I would recommend.

      I’m not saying it’s not possible with a PIC, but personally I’d be terrified of trying to do anything that complicated with any of the PICs I’ve used previously.


  12. Bin says:

    Hi, Ted. Thanks for your CommandCam code, I have been working on Directshow weeks, but since the latest Windows SDK never support sample grabber, that stumped me a lot. But thanks for your code, helping me to understand how to make sample grabber working on current SDK. I appreciate for it. 🙂

  13. Paul says:

    Dear Ted,

    i red and found your blog due to the fact that im looking for a serial-send/receive program.

    The serial send program looks very promising but is not completely what i was looking for and also i would need one for receiving data ….. so i came across you blog and red the posts and answer you wrote … here came my idea 😉

    Would you be willing to adjust the proggi as well as to write a receiving proggi too ?
    And yes i would place a donation too !! 😉

    Thanx for any answer,

    best Paul

    • batchloaf says:

      Hi Paul,

      Can you explain a little bit more about exactly what you need to do? If it’s a specific send-and-receive sequence, such as to control a particular piece of equipment or something like that, it might be easy enough to do a one-off custom program to do it.

      To be honest though, when I need to automate some serial interaction with a device – anything involving more than just simple one way communication – I normally just use a Python script to do it, which is really convenient and effective. Python is 100% free to download and it only takes a couple of minutes to install. You wouldn’t need to learn very much at all to begin using it either, but it provides enormous flexibility in return for minimal time investment.

      You can see a simple Python serial example in this comment I wrote to Wim on the SerialSend page:


      • Paul says:

        Dear Ted,
        thank you for your fast reply .. i wasn’t in anymore yesterday that’s why my late reply right now.
        Ok, the thing is this .. im programming in Filemaker(DB system) for a friend of mine, he’s optician and has an automated phoropter(serial connection).
        The thing is 😦 Filemaker doesn’t handle direct send/receive date to the serial connector, that’s why i have to trigger another program to generate a file in case of receiving and also to send a file to the serial port.

        So i came across your blog and thought ill ask you 😉

        You mentioned python, i just had a small look at it .. looks promising .. but ill have right now no clue of it … i need an exe-file ..is it possible to compile that with python ?

        What i know is :
        – the serialport should be selectable
        – the serial post setting are all the same(parity and so on)
        – it should write/read txt-files

        and i have to run/call it like :
        – sendserial.exe port=1 textfile2send.txt
        – receive.exe port=1 textfile2write.txt

        is this also possible with python ?

        Thanx for your time, i appreciate this very much !!

        Best Paul

      • Paul says:

        Ok i got a small script working 😉 ..not bad for a couple of hours reading and testing, since i’ve never done something with python :
        import serial ## Load the serial library
        ## Select and configure the port
        ser = serial.Serial(port=0, baudrate=9600, bytesize=8, parity=’N’, stopbits=1, timeout = 5)
        ## open text file
        text_file = open(“workfile.txt”, ‘w’)
        text_file = open(“workfile.txt”, ‘r+’)
        ##read serial port and write into textfile
        ## close the serial connection and text file
        ## Close the port so other applications can use it.
        print “Info: program closed”

        but as you can imagine not completely the way i would like to have it 😦
        And most important it should be run as a standalone … and that seems to be tricky

        Any comments and help are welcome 😉

      • batchloaf says:

        Hi Paul,

        Sorry, but I got totally sidetracked and forgot to get back to you. Hopefully you solved your problem during the intervening months. I’ve just been going back through the unread emails in my inbox and I spotted a wordpress update alerting me to your long unread comment! Sorry about that.

        By the way, what I used previously to create a standalone exe file from my Python program was a tool called py2exe. It worked really well for me, but I did find it silghtly tricky to configure for some types of program. My guess is that what you were trying to do wouldn’t be too difficult to package as an exe file with py2exe though.


  14. jenu says:

    Hai, I saw your code for generating PWM using dsPIC30f. I’ve one doubt regarding the PDC1 value. How did you calculated it?


  15. Alpha says:

    Hello, Mr.batchloaf i’m newbie with PIC in linux. And i don’t know how to write hex file to PIC i try to using pk2cmd but not work! output: (Program Memory Error)
    and my compiler is xc16 .. thz for your recommend

    • batchloaf says:

      Hi Alpha,

      When I installed pk2cmd on Linux previously, I needed to install the libusb-dev package also. After downloading the file “pk2cmdv1.20LinuxMacSource.tar.gz”, these were the commands I ran to install pk2cmd on CrunchBang Linux (very similar to Ubuntu):

      sudo apt-get install libusb-dev
      tar xzvf pk2cmdv1.20LinuxMacSource.tar.gz
      cd pk2cmdv1.20LinuxMacSource/
      make linux
      sudo make install

      To use pk2cmd to transfer a hex file,

      • I copy the file “PK2DeviceFile.dat” from the pk2cmd installation folder into the same folder as my hex file.
      • I run pk2cmd as root, so that I have permission to access the hardware device. It may be possible to configure the system so that this isn’t necessary, but for simplicity I’ve always just run it as root.

      My actual pk2cmd command is something like this:

      pk2cmd -PDSPIC30F4011 -F./a.hex -M -T

      …where “a.hex” is the name of my hex file and I’m using a dsPIC30F4011 microcontroller.

      Hopefully, something there will point you in the right direction?


  16. Panos_k says:

    Dear Ted
    Im a student at the department of ECEE in Greece, specialized in power systems. I found this post of yours very interesting ” https://batchloaf.wordpress.com/2015/03/06/using-a-dspic30f4011-to-generating-4-pwm-signals-with-equal-duty-cycles-but-at-90-degree-phase-increments/ ” while searching for a solution in one of my projects. I want to generate a 6 pwm signals with equal duty cycles but at 60 degree increments to drive a 6 thyristors’ bridge. Is it possible to genarate these signals with my dsPIC30F4011 ?
    Thank you in advance.

    • batchloaf says:

      Hi Panos,

      Can you tell me a bit more about the specific requirements? Such as the following…

      1. Is the frequency fixed?
      2. What is the frequency?
      3. What is the required range of duty cycle?
      4. How does the duty cycle vary?

      If you can supply this information, I’ll try to think of a way of doing it.


  17. Panos_k says:

    Hi Ted,
    Thank you very much for your interest!
    Yes the frequency will be fixed at 300kHz and the duty cycle will be variable(0-100%).
    Every pwm signal will have a 60 degree incriments from the previous, so we have 6 pwm signals with 60 degree phase shift from one to another.
    Any help will be appreciated!


    • batchloaf says:

      Hi Panos_k,

      Sorry, I was snowed under with work and I never got a chance to get back to looking at your problem. Hopefully you got it solved in the meantime?


  18. gunz says:

    Hi Ted,
    How can i use PWM port for push-pull mode in your code”PWM output on 2 channels of the dsPIC30F4011 with equal duty cycle and 180 degrees out of phase” but i want to use only PWM1H/1L

    thank you

  19. John Rogers says:

    Hi Ted,

    Thanks, so much, for comprinter! I use your “serial.c and “comprinter.c” for communications to / from USB virtual COM ports. Your code is the most straightforward, well documented, and seems to be bulletproof. I donated a small amount (all I can afford right now), but my appreciation is much, much greater.

    Best Regards,


  20. Bharath K R says:

    Thank You for providing such an awesome blog….. All the information are useful… Thanks again.

  21. manniza says:

    Curious, what would someone the TCP/IP code look like if you were controlling something that had a simple ASCII protocol. I’m thinking like the Cisco VTC Codecs.
    They have simple commands like:
    xConfiguration SerialPort BaudRate:

    Click to access sx80-api-reference-guide-tc71.pdf

    • batchloaf says:

      Hi Manniza,

      I’m afraid I don’t know much about Cisco VTC codecs, so I’m probably not the best person to advise. However, from what I can see in the PDF you linked, it looks like a command line interface is already provided for sending the codes, so perhaps you could just use that if you want to script/automate the process of sending configuration settings?


  22. MC Briers says:

    Thank you so much for these EXTREMELY useful programs. I am now able to build the automated-photogram-turtable-thingimadoodle I’ve been ‘designing’ for years!

  23. gapguillen says:

    Hi Ted … I want to thank you because your posts motivated me to do some simple videos with dsPIC30F2010 and dsPIC30F4013 microcontrollers. I hope you have some time to see them one day because I put reference your blog.

    My channel on youtube is: https://www.youtube.com/user/gapguillen/videos

    I am an engineer in electronics and I have the desire to make a sphygmomanometer and / or an ultrasonic nebulizer. I think the technology should be available to every human being regardless of wealth or poverty.

    My question is this: You know of any tutorial or useful book about bioelectronics? … Also about programming with dspic30fxxxx or pic18fxxxx?

    Greetings from Mexico

  24. Brian Butler says:

    Hi Ted. I have just made the break in to DSP after nearly twenty years of programming 16f devices in assembler and now realise that I have to learn C (Which I have been avoiding for a long time until a week ago). Your examples have been useful and I have got a DSpic30f4013 doing simple things as a result, so thanks. There is one thing I can’t seem to find and that is a clear list of the assembler identities ( If that is the correct term) that are needed by C. I note that some have an underscore in front of them e.g. TRSID = 0 then there are others that are written as _LATD0=1, I have looked at the specific inc file in XC16 but it dose not look that simple.
    Regards Brian

    • batchloaf says:

      Hi Brian,

      I know just what you mean! Where on earth is the actual list of all those register #defines and so on?! I struggled with this for a long time and I’m afraid I never really identified a document that was quite what I was looking for. Over time, however, I did figure out most of what I was wondering about. The documents I find indispensable are:

      1. The dsPIC30F4011 datasheet (you would need dsPIC30F4013 of course).
      2. The dsPIC30F Family Reference Manual – this is actually much more useful than the datasheet.
      3. The XC16 C Compiler User’s Guide.
      4. The header file for the exact chip you’re programming – for you it would probably be called “p30f4013.h”. You should find it somewhere in the install directory of your XC16 compiler. It will probably be inside a folder called “support” or something like that. The header file looks scary at first, but at the end of the day it’s the place where all the #defines you’re wondering about are actually listed. Once I finally started dipping into it, I found it’s one of the most useful pieces of documentation!

      From time to time, I’ve also looked at

      1. 16-Bit Language Tools Libraries Reference Manual

      In a nutshell, any #defined name starting with an underscore (e.g. “_LATA0”) is a bit field with

    • in a register – that is to say a group of one or more bits within one of the 16 bit registers. It provides a convenient way of setting a specific group of bits in a register without changing all the other bits. For example, in the case of “_LATA0” it lets you set the level of one output pin in Port A without affecting the other output pins in that port. The following are exactly equivalent by the way:
      • _TRISA0 = 1;
      • TRISAbits.TRISA0 = 1;

      Both the _TRISAx bits and the TRISAbits bits structure are defined in “p30F4013.h” to refer to the exact same memory location at TRISA (but just one bit out of the 16 in the register).

      Hope that helps!