void DatabinIntegerAdd(char * binID,char * keyName, long val)

void DatabinRealAdd(char * binID, char * keyName, double val)

void DatabinStringAdd(char * binID, char * keyName, char * val)

Needs["SymbolicC`"]

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Open a connection to an Arduino and upload the required sketch to the device:

arduino=DeviceOpen["Arduino","COM3"];

Set the Pulse Width Modulation of the duty cycle of pin 3 to be 50%:

DeviceWrite[arduino,3->(128/255)]

Write a value of 0 to digital pin 10:

DeviceWrite[arduino,10->0]

Write a Pulse Width Modulation duty cycle to pin 5 that corresponds roughly to 2.5 volts for some devices:

DeviceWrite[arduino,5->Quantity[2.5,"Volts"]]

Read from multiple analog input pins:

DeviceRead[arduino,{{"A0","A1"}}]

Read from pin 4, using "ReturnFunction" to compare the value to 1:

DeviceRead[arduino,{4,"ReturnFunction"->(#===1&)}]

Read the value from analog pin A3, applying a conversion function to turn the value into inches:

DeviceRead[arduino,{"A3","ReturnFunction"->(Quantity[#*(1.123/4.7),"Inches"]&)}]

Get the most recently read value for a particular pin:

arduino["PinConfigurations"]["A3"]["LastReadValue"]

Upload a SymbolicC function to the Arduino that adds two numbers and the number 1000 together:

Needs["SymbolicC`"]

DeviceConfigure[arduino,"Upload"->{"Functions"-><|"mySymbolicCFunc"->CFunction["long","func2",{{"long", "i"},{"long","j"}}, CReturn[ COperator[ Plus, {"i","j",1000}]]]|>}];

Now run the function with the arguments 1 and 20:

DeviceExecute[arduino,"mySymbolicCFunc",{1,20}]

Upload a function to control a servo motor attached to the Arduino on pin 9, taking as its argument the position to rotate the servo to, using the Arduino built-in Servo library:

DeviceConfigure[arduino,"Upload"->{"Libraries"->"Servo",Initialization->"Servo servoMotor;","Functions"-><|"ServoRotate"-><|"ArgumentTypes"->{Integer},"ReturnType"->{},"Code"->"
void servoSet(int position)
{
	servoMotor.attach(9);
	servoMotor.write(position);
}"|>|>}];

Now rotate the servo to the 90 degrees position:

DeviceExecute[arduino,"ServoRotate",90]

The following example requires an LCD to be attached to the Arduino on pins 12, 11, 5, 4, 3, and 2. First upload a simple function that writes a string to the LCD screen:

DeviceConfigure[arduino,"Upload"->{"Libraries"->"LiquidCrystal",Initialization->"LiquidCrystal lcd(12,11,5,4,3,2);
void lcdSetup() {pinMode(13,OUTPUT);digitalWrite(13,HIGH);lcd.begin(16,2);}
byte lcdInitQ = 0;","Functions"-><|"LCDPrint"-><|"ArgumentTypes"->String,"Code"->"
void lcdWrite(char * str)
{
	if(!lcdInitQ)
	{
		lcdInitQ = 1;
		lcdSetup();
	}
	lcd.clear();
	lcd.print(str);
}"|>|>}];

Now, write a string to the LCD screen:

DeviceExecute[arduino,"LCDPrint","Arduino+Wolfram"]

Connect to an Arduino Yun:

DeviceOpen["Arduino",{"/dev/tty.usbmodem1421","BoardType"->"Yun"}]

Make a new databin to upload to:

bin=CreateDatabin[]

Databin[]

Configure the Arduino to use the databin by default:

DeviceConfigure["Arduino","Upload"->"Databin"->bin]

"Upload"->Databin->Databin[]

Upload the current value of the pin "A0" to the bin:

DeviceExecute["Arduino",DatabinAdd,"A0"]

Upload the value of the digital pin 4 to the bin once every second for the next ten seconds:

DeviceExecute["Arduino",DatabinAdd,{4,"Scheduling"->{1,10}}]

Configure the Yun to upload the value of pin "A5" with the key "SensorValue" once every 60 seconds infinitely after starting up:

DeviceConfigure["Arduino","Upload"->"BootFunction"-><|"Code"->DatabinAdd,"Databin"->bin,"Pin"->"A5","Key"->"SensorValue","Scheduling"->60|>]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DeviceOpen, paclet:ref/DeviceOpen])  ▪  (RefLink[DeviceConfigure, paclet:ref/DeviceConfigure])  ▪  (RefLink[DeviceRead, paclet:ref/DeviceRead])  ▪  (RefLink[DeviceWrite, paclet:ref/DeviceWrite])  ▪  (RefLink[DeviceExecute, paclet:ref/DeviceExecute])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Using Connected Devices, paclet:guide/UsingConnectedDevices])}})}})