Contrôle De La Partie Module - Yoctopuce Yocto-I2C Mode D'emploi

Table des Matières

Publicité

import com.yoctopuce.YoctoAPI.*;
import java.util.ArrayList;
public class
Demo
{
public static
{
try {
// setup the API to use local VirtualHub
YAPI.RegisterHub("127.0.0.1");
} catch
(YAPI_Exception
System.out.println("Cannot contact VirtualHub on 127.0.0.1 ("
ex.getLocalizedMessage() + ")");
System.out.println("Ensure that the VirtualHub application is
System.exit(1);
}
YI2cPort
i2cPort;
if
(args.length
i2cPort
} else {
i2cPort
}
if
(i2cPort
System.out.println("No module connected (check USB
System.exit(1);
}
try {
// sample code reading MCP9804 temperature sensor
i2cPort.set_i2cMode("400kbps");
i2cPort.set_i2cVoltageLevel(YI2cPort.I2CVOLTAGELEVEL_3V3);
i2cPort.reset();
// do not forget to configure the powerOutput of the Yocto-I2C
// (for MCP9804 powerOutput need to be set at 3.3V)
System.out.println("****************************");
System.out.println("* make sure voltage levels
System.out.println("* are properly configured
System.out.println("****************************");
ArrayList<Integer>
ArrayList<Integer> received;
toSend.add(0x05);
received
int
tempReg
if((tempReg
tempReg
} else {
tempReg
}
System.out.println(String.format("Ambiant temperature:
} catch
(YAPI_Exception
System.out.println("Module not connected (check identification and USB cable)"
);
}
YAPI.FreeAPI();
}
}
13.3. Contrôle de la partie module
Chaque module peut-être contrôlé d'une manière similaire, vous trouverez ci-dessous un simple
programme d'exemple affichant les principaux paramètres d'un module et permettant d'activer la
balise de localisation.
import com.yoctopuce.YoctoAPI.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class
Demo
www.yoctopuce.com
void
main(String[] args)
ex) {
> 0) {
= YI2cPort.FindI2cPort(args[0] + ".i2cPort");
= YI2cPort.FirstI2cPort();
==
null
|| !i2cPort.isOnline()) {
toSend
= new ArrayList<>(1);
=
i2cPort.i2cSendAndReceiveArray(0x1f, toSend,
= (received.get(0) << 8) + received.get(1);
& 0x1000) != 0) {
-= 0x2000;
// perform sign extension
&= 0x0fff;
// clear status bits
ex) {
{
13. Utilisation du Yocto-I2C en Java
+
running");
cable)");
*");
*");
2);
%.3f",
tempReg/16.0));
97

Publicité

Table des Matières
loading

Table des Matières