The only exception is the device name of the USB-to-TTL device.
Arduino Delphi Serial Communication In Java How To Send TextThe tutorial is divided into two parts: In the first part, it is explained how to send text (digits) from a Java Application to an Arduino.Moreover, the Arduino will print out the digits to an LCD module (LCM1602 IIC V1).
In the second part, basically the same Java application is used to send digits to the Arduino but this time with the help of a USB-to-TTL module. As a result, the Arduinos standard serial port can be used by the Arduino IDE to print the received digits to the serial monitor. The other three pins have the exact same names on the Arduino: GND goes to GND, SDA to SDA, and SCL to SCL. Arduino Delphi Serial Communication In Java Code Just WaitsBasically, the code just waits for bytes ready to be read by the serial port. If a byte was read, it is printed out to the LCM1602 IIC V1 module. LiquidCrystalI2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ). I made use of Maven to set up the dependency between my Java project and the jSerialComm library. Therefore, it is very likely that you need to change this argument value. You can find out the device name of your Arduino Uno by having a look to the Arduino IDE. In order to upload code to an Arduino, you have to select the correct device name of the corresponding Arduino. Luckily, the same device name is needed by the jSerialComm library. So simply copy the device name from your Arduino IDE to the Java source code. Sometimes, I have problems executing this code, if I use cheap Arduino clones. Luckily, it always executes perfectly on my original Arduino Uno from Italy;). As a result, the received digits can be viewed from the Arduino IDEs serial monitor (Tools - Serial Monitor). Unfortunately, as a consequence, the standard USB connection cannot be used by the Java application since the serial monitor will already catch the serial port as soon as we open it. As we will use this adapter only to send data from the Java application, we can ignore the RX pin. VCC must be connected to the Arduinos 5V pin, GND must be connected to the Arduinos GND pin, and TX must be connected to the Arduino digital pin 5 (also other digital pins can be used). Arduino Delphi Serial Communication In Java Software Serial ObjectWhen a software serial object is initialized, it requires the pin numbers of the receive and transmit pin. As we do not plan to transmit text from the Arduino Uno, we can set the transmit pin to any number. SoftwareSerial sserial(5,6); receive pin (used), transmit pin (unused).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |