NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Serial comunication between Nerdkit and an MS Excel sheet
October 29, 2011 by sask55 |
I have decided to post a more detailed example of a direct serial link between the Nerdkit and an excel sheet. I do not feel qualified to give an explanation of the possible advantages and disadvantages of this type of Nerdkit/PC link. I have used this type of two way serial link many of times to achieve precise PC control of up to 3 stepper motors at once and relay circuit control. The inherent power of excel makes data processing charting and other detailed analyses quick and relatively simple on data received from the Nerdkit. In fact this type of serial connection is just about the only system I use to set up a link between the PC and the Nerdkit, It has been fast enough for my needs. First set up the VBA communication modules. Follow the detailed instructions at. link to VBA serial communication setup You should not be concerned about the VBA code. In most cases it will not be necessary to have an understanding of any of that code. Once you have the modules in place they work in the background you don’t even know that they are there. You will likely have to have a basic understanding of basic VBA coding to write modules to make efficient use of the connection. I would recommend one simple addition to the existing modules to help you confirm that the serial connection is open and ready to send/receive data. Place the one additional line of code in module that opens the com port.
I have found that it is very useful to have an on the sheet indication of the state of the serial connection. Often after working in the VBA editor or using cmd.com to change coding on the micro it is necessity to re-establish the serial connection to your Excel sheet. In order to see what the current state of the connection is, click the open connection button on “sheet1” of the excel workbook. The number displayed in cell A4 will indicate if the com connection is actually open. You are looking for a 0 (zero) which should mean that excel is ready to read/write on the serial. A -1 can usually be corrected by clicking the close button then clicking the open button again. A 5 indicates that excel thinks the com port is in use by someone else and can be corrected by unplugging the Nerdkit USB cable from the PC for a second. After you have established a viable serial connection between the PC and the nerd kit you may wish to try it out. I am posting some code to set up a simple two way data swap between the Nerdkit and the PC. I wanted to post an example that would clearly demonstrate that the connection is bidirectional and that the data from the Nerdkit is ending up in the excel cells that we intended. Using VBA to place incoming data in appropriate cells and the built in features of excel almost anything is possible. From this example I hope that it will be apparent how powerful and useful this type of connection could be. Place this VBA code in a module that can be triggered from a control button on “sheet1’. Ether make a new control button or use your existing read button.
Use this code on the Nerdkit.
Connect Nerdkit USB cable to the PC. Make sure the com port matches up with the VBA code(com4). Power up the Nerdkit. Click the open port button on the excel sheet. Check that you have a 0 in cell A4. Click on the command button that will run the VBA module listed here. Enter the desired table size for the first test (cells A7 and A8), don’t forget to press enter after change. Click on the command button to run the VBA code and hopefully receive the data from the Nerdkit. This setup is working on my system. There is a small glitch that occurs when my VBA module ends I am looking into the exact nature of that odd result. I would be very interested in knowing if anyone gets this working. Darryl |
---|---|
October 29, 2011 by sask55 |
I noticed the link I posted does not work, I will try again. link to Serial port communication in excel Darryl |
October 30, 2011 by JKITSON |
Thanks for the link to SERIAL PORT COMM.
This may be the basis I am looking for to merge data from
my TRACTOR PULL SLED to a spread sheet for each puller.....
via a radio link from the sled.. |
October 31, 2011 by sask55 |
I should also mention that you will have to change the baud rate in the excel VBA code to match up with the Nerdfkit baud rate. The baud rate is set in the open port sub listed above. You must simply change the baud=9600 to baud=115200. Darryl |
Please log in to post a reply.
Did you know that talking to the microcontroller over the USB/Serial link is easy under Windows, Linux, and OS X? Learn more...
|