AN0007 Arduino plaatina ühendus
“
Tooteteave
Tehnilised andmed
- Toote nimi: ARDUINO-PLATINUM COMM-i ABIDOKUMENT
- Tootja: Dynament Limited
- Aadress: 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 - Väljaanne: 1.2, Kuupäev: 09
Toote kasutusjuhised
Anduri ühendamine
See andmeleht kasutab näitena Arduino Megatample. Connect as
järgmine:
- 5v -> 5v Arduino tihvt
- 0v -> Arduino maandus
- Saatja -> Arduino RX1
- Rx -> Goes to the output of the potential divider. The input
goes to Arduino Tx
Voltage Ühilduvus
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.
Arduino IDE seadistamine
- Download the newest version of the Arduino IDE software from
the Arduino websaidile. - Select the Arduino board, processor, and port in the tools
rippmenüüst.
Koodi üleslaadimine
- Kopeeri antud example kood Arduino IDE-sse.
- Laadige kood Arduinosse üles noolele klõpsates.
- Avage jadapordi monitor, et view andmeedastus.
KKK
Q: What should I do if I have an Arduino Uno with only one comm
sadamasse?
A: Connect the Platinum Sensor to that port. When using the
serial monitor, it will also show the transmitted hex.
"`
Rakendusmärkus AN0007
ARDUINO to PLATINUM COMMS HELP DOCUMENT
Dynament Limited
Hermitage Lane'i tööstuspark, Kings Mill Way, Mansfield, Nottinghamshire NG18 5ER, Ühendkuningriik. Tel: +44 (0)1623 663636
email: sales@dynament.com www.dynament.com
AN0007
1.2. probleem
09
Change Note 805
1. lehekülg 14-st
Sisu
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. probleem
09
Change Note 805
2. lehekülg 14-st
Connecting the Sensor This data sheet uses the Arduino Mega as an exampnt. Ardunio Megal on rohkem kui üks sideport, seega kasutatakse sideporti 1 anduriga suhtlemiseks ja sideporti 0 arvutisse printimiseks.
Arduino kasutab 5 V loogikapinget, samas kui Platinum Sensor kasutab 3.3 V, seega anduri kahjustamise vältimiseks on vaja vol...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 Arduino tihvt
0v -> Arduino maandus
Saatja -> Arduino RX1
Rx -> Goes to the output of the potential divider. The input goes to Arduino Tx
AN0007
1.2. probleem
09
Change Note 805
3. lehekülg 14-st
After this is complete your Platinum Sensor should be connected as shown:
Figure 2: Sensor is shown upside down with a solder adapter
Kui kasutate Arduinot, millel on ainult üks sideport (nagu Arduino Uno), peate selle sellega ühendama, kuid jadapordi monitori (näidatud hiljem) kasutamisel kuvatakse ka edastatud heksaedastuskoodi.
AN0007
1.2. probleem
09
Change Note 805
4. lehekülg 14-st
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. probleem
09
Change Note 805
5. lehekülg 14-st
Kopeeri selles eksample 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. probleem
09
Change Note 805
6. lehekülg 14-st
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. probleem
09
Change Note 805
7. lehekülg 14-st
Figure 7: The Serial Montor shows the packet that has been received
AN0007
1.2. probleem
09
Change Note 805
8. lehekülg 14-st
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.
Järgmisena tuleb seadistusfunktsioon. Seda koodi käivitatakse käivitamisel ainult üks kord. See käivitab pordid Serial0 ja Serial1. Serial0 kuvatakse jadapordi monitori ekraanil. Serial1 on port, mida kasutatakse anduriga suhtlemiseks.
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. probleem
09
Change Note 805
9. lehekülg 14-st
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. probleem
09
Change Note 805
10. lehekülg 14-st
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
Joonistel 10 ja 11 on näidatud vastavalt väljuv ja sissetulev heksakood koos veeruga, mis näitab, millise käsuga on tegemist.
Figure 10: Outgoing Packet Description
AN0007
1.2. probleem
09
Change Note 805
11. lehekülg 14-st
Figure 11: Incoming Packet Description
Pange tähele, et gaasi näit on kümnendmurru, mitte täisarv. See kümnendmurru formaat on IEEE-754 ja selle teisendamiseks võite kasutada sellist veebipõhist konverterit. Gaasi väärtus näitab antud juhul -250 (kuna see oli sel ajal vearežiimis).
AN0007
1.2. probleem
09
Change Note 805
12. lehekülg 14-st
Serial.read() kasutamine
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.
Seda saab teha mitmel erineval moel, siin teen ma andmete vasakule nihutamise ja seejärel VÕI-operaatori abil nende ühendamise.
Selle koodi abil, kui readByte1 on 0x34 ja readByte2 on 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 // see seejärel VÕI-tehtega asendatakse, kus 0x34 teeb tulemuseks 0x1234.
Teine võimalus selleks on panna väärtused massiivi ja seejärel teisendada massiiv soovitud tüüpi:
AN0007
1.2. probleem
09
Change Note 805
13. lehekülg 14-st
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.
Sel juhul on readArray char-massiivi pointer. (float*)readArray See osa teisendab massiivi ujukkoha pointeriks ja seejärel lisatakse ette *, et saada ujukkoha väärtus.
Täiustatud konversioonimärkmed
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. probleem
09
Change Note 805
14. lehekülg 14-st
Dokumendid / Ressursid
![]() |
DYNAMENT AN0007 Arduino plaatina ühendusmoodul [pdfKasutusjuhend AN0007 Arduino to Platinum COMM, AN0007, Arduino to Platinum COMM, to Platinum COMM, Platinum COMM |