AN0007 Arduino do Platinum COMM
“
Informácie o produkte
Špecifikácie
- Názov produktu: ARDUINO na PLATINUM COMMS POMOCNÝ DOKUMENT
- Výrobca: Dynament Limited
- Adresa: Hermitage Lane Industrial Estate, Kings Mill Way,
Mansfield, Nottinghamshire, NG18 5ER, UK - Contact: Tel: 44 (0)1623 663636, Email: sales@dynament.com,
Website: www.dynament.com - Vydanie: 1.2, Dátum: 09
Návod na použitie produktu
Pripojenie snímača
Tento technický list používa Arduino Mega ako príklad.ample. Connect as
nasleduje:
- 5V -> 5V pin Arduina
- 0V -> Uzemnenie Arduina
- Tlmočníctvo -> Arduino RX1
- Rx -> Goes to the output of the potential divider. The input
goes to Arduino Tx
Voltage Kompatibilita
The Arduino uses 5v logic high while the Platinum Sensor uses
3.3v. Use a voltage divider with suggested values for R1 and R2 as
4K7 to prevent damage to the Sensor.
Nastavenie Arduino IDE
- Download the newest version of the Arduino IDE software from
the Arduino webstránky. - Select the Arduino board, processor, and port in the tools
rozbaľovacej ponuky.
Nahrávanie kódu
- Skopírujte poskytnutý exampkód do Arduino IDE.
- Nahrajte kód do Arduina kliknutím na šípku.
- Otvorte sériový monitor pre view prenos dát.
FAQ
Q: What should I do if I have an Arduino Uno with only one comm
prístav?
A: Connect the Platinum Sensor to that port. When using the
serial monitor, it will also show the transmitted hex.
“
Aplikačná poznámka AN0007
ARDUINO to PLATINUM COMMS HELP DOCUMENT
Dynament Limited
HermitagPriemyselný areál e Lane, Kings Mill Way, Mansfield, Nottinghamshire, NG18 5ER, Spojené kráľovstvo. Tel.: +44 (0)1623 663636
email: sales@dynament.com www.dynament.com
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 1 z 14
Obsah
Dynament Limited …………………………………………………………………………………………………….1 Connecting the Sensor……………………………………………………………………………………………..3 Arduino IDE ………………………………………………………………………………………………………………5 Code Explanation……………………………………………………………………………………………………..9 Packet Breakdown ………………………………………………………………………………………………….11 Using Serial.read() ………………………………………………………………………………………………….13
Advanced Conversion Notes……………………………………………………………………………….14
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 2 z 14
Connecting the Sensor This data sheet uses the Arduino Mega as an exampArdunio Mega poskytuje viac ako jeden komunikačný port, preto sa komunikačný port 1 používa na komunikáciu so senzorom a komunikačný port 0 sa používa na tlač do počítača.
Arduino používa 5V logickú vysokú úroveň, zatiaľ čo Platinum Sensor používa 3.3V, takže aby sa predišlo poškodeniu senzora, je potrebné...tage divider must be used. Suggested values for R1 and R2 are 4K7.
Figure 1: Lowers the voltage to useable level
The Sensor transmit line going to the Arduino receive doesn’t need a divider as 3.3v is an acceptable input to the Arduino.
In order to power the Sensor it must be connected to 5v and 0v. To do this you can use the pins on the Arduino.
After this is complete, the sensor should now have the following pins connected:
5V -> 5V pin Arduina
0V -> Uzemnenie Arduina
Tlmočníctvo -> Arduino RX1
Rx -> Goes to the output of the potential divider. The input goes to Arduino Tx
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 3 z 14
After this is complete your Platinum Sensor should be connected as shown:
Figure 2: Sensor is shown upside down with a solder adapter
Ak používate Arduino s iba jedným komunikačným portom (ako napríklad Arduino Uno), budete ho musieť pripojiť k nemu. Keď však použijete sériový monitor (zobrazený neskôr), zobrazí sa aj prenášaný hexadecimálny kód.
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 4 z 14
Arduino IDE Go to the Arduino website and download the newest version of the Arduino IDE software. Once installed you should see the following screen:
Figure 3: Arduino home screen
In the tools drop down menu select the Arduino board, processor and port you are using:
Figure 4: Select Board, Processor and Port options
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 5 z 14
Kopírovať v tomto príkladeample code: void send_read_live_data_simple(); void receive_read_live_data_simple();
void setup() { Serial.begin(38400); Serial1.begin(38400);
}
void loop() { send_read_live_data_simple(); receive_read_live_data_simple(); delay(5000);
}
void send_read_live_data_simple(){ // 0x10, 0x13, 0x06, 0x10, 0x1F, 0x00, 0x58 Serial1.write(0x10); Serial1.write(0x13); Serial1.write(0x06); Serial1.write(0x10); Serial1.write(0x1F); Serial1.write(0x00); Serial1.write(0x58);
}
void receive_read_live_data_simple(){ while (Serial1.available()) { Serial.print(Serial1.read(), HEX); Serial.print(“|”); } Serial.println();
}
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 6 z 14
Figure 5: Code ready to upload
Click the arrow to upload the code to the Arduino. After the Arduino has been programmed open the serial monitor.
AN0007
Figure 6: Open the Serial Monitor
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 7 z 14
Figure 7: The Serial Montor shows the packet that has been received
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 8 z 14
Code Explanation The Arduino IDE uses C++ to program the Arduino.
This line is a forward declaration. This is used to tell the Microcontroller that further down in the program the `send_read_live_data_simple’ function and the `receive_read_live_data_simple’ function will be called.
Nasleduje funkcia nastavenia. Tento kód sa spustí iba raz pri štarte. Spustí porty Serial0 a Serial1. Serial0 je to, čo sa zobrazuje na obrazovke sériového monitora. Serial1 je port na komunikáciu so senzorom.
This is the main loop, this code gets repeatedly looped. You can see by reading the function names that it sends a request to read a simplified version of the live data struct. Then it reads the receive port to read the reply. After this the Microcontroller waits 5000mS.
This function writes the request to get the live data simple struct to serial port 1. As previously mentioned if you only have one serial port you should change Serial1 to Serial. To see the full list of commands, refer to the Premier sensor Communications protocol document. Here is the part of the document that tells you what to write for this command:
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 9 z 14
This function loops the read function while there is still data to be received from the Platinum Sensor. Serial1.read() reads the data from Serial1 which is connected to the sensor and prints it on Serial0 so it can be seen on the serial monitor. The character `|’ is then printed to break up each byte that is received to make it clearer on the serial monitor.
After this is complete it writes a new line to the serial monitor.
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 10 z 14
Packet Breakdown Figure 8 and 9 show the output of a serial decoder connected to the receive and transmit lines.
Figure 8: Outgoing Packet
Figure 9: Incoming Packet
Obrázok 10 a 11 zobrazuje odchádzajúci a prichádzajúci hexadecimálny kód so stĺpcom, ktorý ukazuje, o ktorý príkaz ide.
Figure 10: Outgoing Packet Description
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 11 z 14
Figure 11: Incoming Packet Description
Upozorňujeme, že údaj o plyne je desatinné číslo, nie celé číslo. Toto desatinné číslo je vo formáte IEEE-754, na jeho prevod môžete použiť online prevodník, ako je tento. Hodnota plynu v tomto prípade ukazuje -250 (pretože v tom čase bola v chybovom režime).
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 12 z 14
Používanie funkcie Serial.read()
The previous code only printed the data received to the serial monitor, if you want to save the data in variables you will need to do some further processing. The packet you receive is split into bytes, because of this you will need to concatenate some of this data into variables. Serial1.Read() returns an int (which for Arduino is 16 bits), however, only the first 8 bits are used. Because of this we can copy it into a smaller data type that is only 8 bits, in this case I will use char.
for the packets that are only a byte long, this works fine:
For the packets that are 2 bytes or 4 bytes long you will need to concatenate the data.
Môžete to urobiť mnohými rôznymi spôsobmi, tu urobím len posunutie dát doľava a potom ich spojiť operátorom ALEBO.
Pomocou tohto kódu, ak je readByte1 0x34 a readByte2 je 0x12.
(int)readByte2
// this converts the 0x12 into 0x0012.
(int)readByte2 << 8
// this shifts the bits over by a byte making it 0x1200.
(int)readByte2 << 8 | readByte1 // toto sa potom spracuje operáciou OR, pričom 0x34 vytvára 0x1234.
Ďalším spôsobom, ako to urobiť, je vložiť hodnoty do poľa a potom toto pole previesť na požadovaný typ:
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 13 z 14
chars are a byte long, whereas float is 4 bytes long. Because of this if we make an array of 4 chars with our values in it and change the type to float.
V tomto prípade je readArray ukazovateľ na pole znakov. (float*)readArray ho pretypuje na ukazovateľ na číslo s float a potom sa na začiatok pridá hviezdička *, aby sa získala hodnota tohto čísla s float.
Pokročilé poznámky k konverzii
1. Serial.read() returns int instead of char because errors will return negative values. Your program should check for this.
2. uint8_t and uint16_t should be used in place of char and int respectively, as these types do not have a standard size (on my PC int is 32 bits whereas on the Arduino it is 16 bits).
3. The comms protocol contains byte stuffed characters (also known as control characters), this is explained in more detail in the tds0045 Premier sensor Communications protocol document. Because of this the read live data simple packet will occasionally be bigger than expected.
AN0007
1.2. vydanie
09. 04. 2025
Change Note 805
Strana 14 z 14
Dokumenty / zdroje
![]() |
DYNAMENT AN0007 Arduino na Platinum COMM [pdf] Používateľská príručka AN0007 Arduino to Platinum COMM, AN0007, Arduino to Platinum COMM, to Platinum COMM, Platinum COMM |