Advertisement
Guest User

read neje laser temp via arduino

a guest
Jun 11th, 2022
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <SoftwareSerial.h>
  3.  
  4. #define LASER_INPUT_PIN 2 //aka D2
  5. #define TEMPERATURE_OUTPUT_PIN 5 //aka D5 PWM
  6. #define TEMPERATURE_BYTE_INDEX 4 // see https://i.imgur.com/AcpoeKa.png
  7.  
  8. #define DEBUG //print temp value on serial con
  9.  
  10. SoftwareSerial softSerial(LASER_INPUT_PIN, 3); // RX, TX
  11.  
  12. byte laser_packet[7];
  13. byte index = 0U;
  14.  
  15. void setup() {
  16. #ifdef DEBUG
  17.     Serial.begin(9600);
  18. #endif
  19.     softSerial.begin(200);
  20.     pinMode(TEMPERATURE_OUTPUT_PIN, OUTPUT);
  21. }
  22.  
  23. void loop() {
  24.    //analogWrite(TEMPERATURE_OUTPUT_PIN, 170);
  25.     while (softSerial.available() > 0) {
  26.         byte b = softSerial.read();
  27.         if (b == 0xFF) { //start of packet
  28.             index = 0U;
  29.         }
  30.         laser_packet[index++] = b; //store byte
  31.     }
  32.     if (index == 7) {
  33. #ifdef DEBUG
  34.         Serial.print("Temp: ");
  35.         uint16_t temp = laser_packet[TEMPERATURE_BYTE_INDEX];
  36.         Serial.print(temp);
  37.         Serial.println("C");
  38. #endif
  39.      
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement