Aegidius
 Plüss   Aplulogo
     
 www.aplu.ch      Print Text 
© 2021, V10.4
 
  NxtLib
 
 

NEW:

tempsensor
Lego NXT Temperature Sensor (9749) is now supported with the EV3
in direct and autonomous mode.

 

Data Logging (Direct Mode)

Purpose: Use the EV3 brick as a wireless remote measuring device and transfer data to a PC via Bluetooth or over the Internet. In this example data is collected periodically every 100 ms and shown in a simple graph.

For the purpose of the demonstration the EV3 uses a NXT light sensor, but it may be replaced by any other measuring device (color sensor, temperature sensor, distance sensor, prototype board, etc.).


import ch.aplu.ev3.*;
import
 ch.aplu.util.*;

public
 class EV3DataLogger
{
  
public EV3DataLogger()
  
{
    LegoRobot robot 
= new LegoRobot();
    GPanel g 
= new GPanel(0, 10000, 0, 1000); 

    g.title("EV3 Data Logger");
    
drawGrid(g);
    NxtLightSensor ls 
= new NxtLightSensor(SensorPort.S1);
    robot.
addPart(ls);
    
int t = 0;  // time in ms
    
int dt = 100; // time step in ms
    HiResAlarmTimer timer 
= new HiResAlarmTimer(dt);
    
while (true)
    
{
      
while (timer.isRunning())
      
{
      
}  // Wait until period is over
      timer.
start();
      
int value = ls.getValue();
      g.
title("Time: " + (t / 1000.0) + " s  Value: " + value);
      
int x = t % 10000;
      
if (x == 0)
      
{
        
drawGrid(g);
        g.
move(x, value);
      
}
      
else
        g.
draw(x, value);

      t 
+= dt;
    
}
  
}

  
private void drawGrid(GPanel g)
  
{
    g.
clear();
    
for (int x = 0; x <= 10000; x += 1000)
      g.
line(x, 0, x, 1000);
    
for (int y = 0; y <= 1000; y += 100)
      g.
line(0, y, 10000, y);
  
}

  
public static void main(String[] args)
  
{
    
new EV3DataLogger();
  
}
}

Execute EV3DataLogger using WebStart (EV3 brick with EV3DirectServer needed).

ev3_datalogger


Discussion: Remote data sampling is is extremely simple in EV3 direct mode, because in direct mode, the PC controls the EV3 anyway. No additional client-server code is necessary. With an EV3 WLAN connection to an Internet router, the PC can be located anywhere far away. The program remains unchanged.

Instead of a PC, a mobile device (smartphone, tablet) can be used to monitor data remotely over the Internet.

Since the HiTechnic SuperPro Prototype Board board is fully supported in EV3 autonomous and direct mode, few additional electronics is needed to control actuators (relays, motors, pumps, etc.) remotely. Consult the NXT related examples for more information.