Friday, November 15, 2013

Controlling Your Test and Measurement Instruments Remotely with Arduino

In this post we will look at how to use the new Arduino Yun to connect to, control, and get data from test and measurement instruments remotely using WiFi. The Arduino Yún is a open source development board based on the ATmega32u4 microcontroller and the Atheros AR9331 processor. The Atheros processor is equipped with Linux distribution based on OpenWRT named Linino. The microcontroller side of the board delivers capabilities such as digital in / out, ADC, DAC, PWM, and more. The processor side of the board offers Ethernet, micro-SD card storage, and WiFi support. What is really cool about  the Yun is how the designers abstracted the communication between the two chips, which allows the microcontroller to easily communicate across WiFi with other devices, such as test and measurement instrumentation, by writing code only for the microcontroller! To learn more about the Arduino Yun click here.

A Yun can act like a WiFi access point which allows it to connect to a WiFi network created by an Ethernet based router (you probably have one of these at home). If an instrument has remote LAN capability, we can use a LAN cable to connect it to the same Ethernet network that the Yun connected to allowing a connection to be established between the two devices. With this connection the Yun can communicate and control the instrument to have it make measurements, output signal, etc. Why would this be useful? Well for instance you could use this to setup a low cost self contained data logging system. The Yun microcontroller could make basic measurements such as temperature and even offer basic digital control of the device you are testing. Then for more complex or high precision measurements you could bring in an instrument, such as function generator or spectrum analyzer and have the Arduino Yun control it. You can then store and retrieve the results from an SD card on the Yun, a Dropbox account that the Yun logs into, or the Yun could connect to a remote computer and send it the results.

Now let's look at a simple example of an Arduino Yun connecting to an instrument remotely making a measurement and then allowing a user to fetch the resulting measurement remotely from the Yun. For this example we will use an Agilent N6705B DC Power Analyzer as the instrument the Yun will communicate with. We will actually use the N6705B to power the Yun and then have the Yun connect to it and get a measurement of its own current draw. Below is the setup with channel one of the N6705B connected to the power input of the Yun.

The N6705B channel one is set for 5 V to power the Yun. The arduino sketch with the code written to implement this example can be seen below with comments to help explain each code line. Refer to the the "#include" libraries in the code, the first one is the Bridge library. This is the library that handles the communication between the microcontroller and the processor. This library allows you to control both the microcontroller and a lot of the processor functions by writing code only for the microcontroller, it takes a lot of complexity out of networking and storage functions in the Yun. The other two libraries, YunClient and YunServer, enable the network communication between the Yun, instrument, and the end user. Right below the libraries we define two network ports and an IP address. The IP address is the network address of the N6705B. It was obtained via the front panel of the N6705B. If you use this code be sure to change the address to the address of the instrument you want to control. The address is used to tell the network who the Yun is trying to communicate with. The port is like the channel that the communication will take place on, test and measurement instruments like the N6705B typically use port 5025. The second port "6666" is the port we will use to fetch the measurement data from the Yun remotely. The object "iClient" will be used to communicate with the N6705B and the object "server" we will use to communicate with a PC that the Yun will send the measurement data to. Notice that in the function setup() we start the Bridge which will establish communication between the microcontroller and the processor. This needs to be done for us to do network communication.

/*In this example Arduino Yun will remotely connect to the N6705B power supply (which is powering 
the YUN). The N6705B is on the same local network as the YUN. The YUN will then remotely via WiFi
connect to the N6705B and measure its current and store the value. A computer then connects to the YUN
over WiFi via terminal to retrieve the measurements */
#include Bridge.h>
#include YunClient.h>
#include YunServer.h>

#define IPORT 5025 //This is the port most if not all agilent instrument use to communicate over LAN
#define CPORT 6666 //This is the port we will connect with a PC to get measurement data
IPAddress ip(192,168,0,18); //create variable with IP address (you will want to plug your own IP address in here)
YunClient iClient; //create client object, the instrument acts as a server so the YUN is the client
YunServer server(CPORT); //create server object to connect to computer
int getData = 1; //bool to track when computer connects

void setup() {
  pinMode(13, OUTPUT); //set LED pin to output
  digitalWrite(13, LOW); //turn LED off, we will turn it on later after we get the measurement data
  Bridge.begin();//start bridge between ucontroller and processor. This can take 2 sec

void loop() {
  iClient.connect(ip,IPORT); //connect to the N6705B
  while(!iClient.connected()) { delay(100); } //loop until connected
  String question = "*IDN?\n"; //SCPI command to get instrument info
  iClient.write((uint8_t*)&question[0], question.length()); //send *IDN? command to N6705B
  String response; //create string to store response
  while(iClient.connected()) { //loop until get the entire response
    if(iClient.available()) {  //if available read response
      char cmd =; //read response from N6705B one character at a time
      if(cmd == '\n') { break; } //If at newline character got message so break out of loop
          else { response += String(cmd); } //add next character to response string
   response = "Connected to: " + response + "\n"; //add heading and endline to string
  question = "MEAS:CURR? (@1)\n"; //SCPI command for measure current at channel 1
  iClient.write((uint8_t*)&question[0], question.length()); //send measure command to N6705B
  String measurement; //create string to store the measurement
  while(iClient.connected()) { //loop until get the entire response
    if(iClient.available()) {  //if available read response
      char cmd =; //read response from N6705B one character at a time
      if(cmd == '\n') { break; } //If at newline character got message so break out of loop
          else { measurement += String(cmd); } //add next character to response string
   measurement = "The Yun current is: " + measurement +" A\n";
   iClient.stop(); //Disconnect from the N6705B
   digitalWrite(13, HIGH);//turn LED on to signal we connected to the N6705B and made a measurement

//************** Now we wait for computer to connect and retrieve data

   server.noListenOnLocalhost(); //Tell Yun to wait look for connection (not just local host connection)
   server.begin(); //Start server
   //Loop until computer connects. I used the terminal on my mac to connect using the "nc" command.
  //Just type "nc 6666" into the command line, of course substitute your YUN's IP address in
   while(getData) { //Loop until computer connects
   YunClient client = server.accept(); //accept a connection and create a client object for it

  if(client.connected()){ //if we are connected to a computer send N6705B and measurement info
    client.write((uint8_t*)&response[0], response.length()); //send instrument information
    client.write((uint8_t*)&measurement[0], measurement.length()); //send current measurement
    client.stop(); //disconnect from computer
    getData = 0; //we are done so set variable to break out of loop

 while(1) { //never ending loop since we are done
  delay(1000); }

In the top section of the main loop we start a connection with the N6705B and send it two commands. In network jargon the N6705B is the server and the Yun is the client. The first command "*IDN?" gets basic information on the instrument we are connected to such as model and serial number. The second command "MEAS:CURR? (@1)" tells the instrument to measure the current on channel one, this is the channel that is powering the Yun. These commands are known as SCPI commands and can be obtained from an instrument's manual. Notice that after each command is sent the Yun reads the response and stores it in a string. Once the exchange is complete the Yun ends the connection with the N6705B and turns on the LED on the board connected to pin 13. This tells the user that the measurement is complete.

Now we need to get the data from the Yun by remotely connecting to it with a PC, in this case the Yun now acts as a server and the PC as a client. This interaction takes place in the bottom section of the code in the main loop. In this section a while loop is used to continuously check if a remote PC is trying to connect. Once a connection is made the Yun sends the data it obtained from the instrument and closes the connection. From there it enters an infinite loop and preforms no other actions.

There are multiple ways for us to collect the data from the Yun at this point using a PC. One way would be to write a simple program in MATLAB or LabView and use their networking libraries to connect to the Yun and retrieve the data. For this example we will use the Terminal on a Mac laptop. Terminal's are found on Linux and Mac based operating systems. For this example we will use the "netcat" or "nc" command which allows us to create a network connection with another network device and read from or write data to that device. To connect with the Yun to get the N6705B data we need its IP address, which is for the Yun used in this example, and the port number, which is 6666 as mentioned earlier. The full command for the Terminal is "nc 6666." Below is a screen shot from a terminal that connected to the Yun and retrieved the N6705B data, which includes the basic N6705B information and the measurement of the Yun's current consumption.

We can see from the fetched data that the Yun's current was ~ 266 mA.

In this blog we looked at how the Arduino Yun can be used to connect to, control, and fetch measurement data from test and measurement instrumentation with remote LAN capability. We stepped through an example using a Yun, an N6705B DC Power Analyzer, and a Mac computer. If you have any comments related to this post use the comments section below and if you have any questions feel free to email me.

Click here for more information on Arduino

Click here more information on the N6705B DC Power Analyzer


  1. This comment has been removed by the author.

  2. I have never seen this type of thing before? Can it be used to do home wiring?
    Harlin |

  3. We help in setting up and Installing Microsoft Office on your computer. We provide Technical Support and other services to you. We help you with great work and other details. We are here to help you. We help you with Microsoft Office and Office installation. We help you with Great technical services at an affordable price.

  4. I just want to tell you that I’m all new to blogging and site-building. I really loved your web page. Very likely I’m want to bookmark your site . You amazingly have remarkable posts. Thanks a bunch for sharing your blog.
    Regards -

  5. Watch all latest movies for free using best movies app Terrariumtvapp

  6. I have been looking for Test and measurement equipment and didn’t found any good company or dealers. Also, I wanted superior quality equipment that could provide accurate results. As it is well known that test and measurement equipment is utilized in numerous fields be it assembling, material examination, or even a lab or electronics field, all take help of measurement equipment to determine different parts of the materials they are analyzing on. In such a scenario you can’t rely on regular brands. I am happy with Omni Control’s services. They have the widest collection of Test and measurement equipment of all brands in their stock. I got my equipment with great features easily with Omni Controls. Thank You for your Blog!

  7. Great Post. Learn more Soldering iron guide Top guardians

  8. appvn is an application store where you can get an enormous number of uses and amusements that you could possibly bounce on the official Google Play Store.

  9. โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

  10. เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

  11. That seems to be a great information. If you are a Quickbook user and need any kind of assistance for managing the software then you can contact Intuit Quickbooks Support for help. They will provide you the best solution for your issue.

  12. Jobs divine is one of the best job consultancy in thrissur. We provide all types of jobs in thrissur. We do have many job vacancies in thrissur. Sign up now for a free account and get thrissur jobs instantly. The candidates who in search of good career in Thrissur can apply and get easily their dream job through jobs divine

    job consultancy in thrissur

    thrissur jobs

    top job placement agency in thrissur

    job vacancies at thrissur

    jobs at thrissur

    thrissur job vacancies

  13. Wonderful blog! I found it while browsing on Yahoo News


  14. If you need quickbooks help and then call Quickbooks Support Phone Number 1800-901-6679. You can also visit us on

  15. Thanks a lot for sharing the content. Really a nice blog and great kind of information is provided by you. We provide quickbooks support phone number +1-800-901-6679.

  16. Our essay writing help service services are very affordable as we provide you with work that is at a golden equilibrium, try our top paper writing services today.

  17. By using SAGE Tech Support user can get expert advice & helps in improving ROI of their business by SAGE accounting software. Enjoy hassle free accounting automation with SAGE 50 with 24/7 help for any kind of issues & errors. The user can dial Toll Free Number +1-855-686-6166 for any issues related to SAGE 50, SAGE 50 C, SAGE 100, SAGE 300, SAGE Payroll, SAGE Enterprise, SAGE One and other SAGE software solutions. Now SAGE 50c popular business solutions for each business who like mobility and flexibility & power of using accounting software anytime, anywhere and on any device. Also dialling SAGE 50 Technical Support Phone Number +1-855-686-6166 user can get detailed help & assistance for invoicing, Custom report, Excel import & export, bills & customer invoice. All types of task like payroll, vendor, taxes, manufacturing, inventory management, Enterprise Resource Planning, Human Resource Management, Customer Relationship Management and tax filing now can be done easily just by single mouse click.
    Sage Support Phone Number

    Sage Support Phone Number USA

    Sage Support Number

    Sage Support

    Sage Technical Support Phone Number

    Sage Technical Support Number

    Sage Technical Support

    Sage Tech Support Phone Number

    Sage Tech Support Number

    Sage Tech Support

  18. Thank you so much for sharing this knowledgeable blog for us, it is truly a great informative site. That is very helpful for us. water pump for house

  19. It is really a useful sharing. I have received a lot of good knowledge from it
    happy wheels

  20. Any student is free to request for our Buy Custom Papers Online as we have the most affordable pricing in the market. We always keep our promise and will deliver the paper within the agreed time and ensure that it is written to meet all the Best Custom Paper standards.

  21. Really great article, Glad to read the article. It is very informative for us. Thanks for posting.Norton™
    provides industry-leading antivirus and security software
    for your PC, Mca, and mobile devices Visit @: - ||

  22. That's great information. I did a search and found your blog. It's been a big help! Thanks for sharing this blog. click here