How can I configure P1-04THM properly to read raw mV inputs in Arduino?

The configuration I want to use (0-39mV) only prints 0.00 regardless of how many mV get inputted to the module. When I configure it to a J type thermocouple input, everything works fine so the wiring and hardware is verified that it is working. When I use the 0-39mV configuration the same thermocouple shows 0 before any mapping is done. When I print THMmodstatus it prints out 0 in all cases. Below is a snippet of the non working code:

 

const char P1_04THM_CONFIG[] = { 0x40, 0x03, 0x60, 0x01, 0x21, 0x09, 0x22, 0x09, 0x23, 0x09, 0x24, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

bool THMmodstatus = P1.configureModule(P1_04THM_CONFIG, card4);

PT711_raw = P1.readTemperature(card4, 1);

Serial.print("PT-711: "); 

Serial.println(PT711_raw, 2);

 

 


Yammos likes this.
  • FACTS_AdamC (AutomationDirect)

    Are you configuring the module before every reading like below? If so, that is likely the cause of your issue. Usually the module would be configured in setup() and then just read in the loop.

    1. void loop(){
    2. const char P1_04THM_CONFIG[] = { 0x40, 0x03, 0x60, 0x01, 0x21, 0x09, 0x22, 0x09, 0x23, 0x09, 0x24, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    3. bool THMmodstatus = P1.configureModule(P1_04THM_CONFIG, card4); //bad <--- Do not run config every loop
    4. PT711_raw = P1.readTemperature(card4, 1);
    5. Serial.print("PT-711: ");
    6. Serial.println(PT711_raw, 2);
    7. }

     

    Expand Post
  • telisaths (Customer)

    Hi Adam,

     

    Thank you for your response. I did have the Array and P1.configureModule function in the loop but when I pulled them out the problem persists. Here is my current entire code, most of it is for other modules but maybe somewhat relevant:

    1. #include <SPI.h>
    2. #include <P1AM.h>
    3. #include <SD.h>
    4.  
    5. const int chipSelect = SDCARD_SS_PIN;
    6.  
    7. // Inputs
    8. float TT711;
    9. float TT712;
    10. float TT721;
    11. float TT722;
    12. float TT761;
    13. float TT791;
    14. float TT792;
    15. float TT793;
    16. float TT794;
    17. double PT711;
    18. float PT711_raw;
    19. double PT791;
    20. float PT791_raw;
    21. float VG781;
    22. float FT791VFR;
    23. float FT791MFR;
    24.  
    25. //Outputs
    26. bool XV791;
    27. bool THMmodstatus;
    28. bool RTD1modstatus;
    29. bool RTD2modstatus;
    30. bool RTD3modstatus;
    31.  
    32. //Sequence Bits
    33. bool XV791_Open;
    34.  
    35. const int card1 = 1; //P1-16CDR digital input/output module
    36. const int card2 = 2; //P1-08ADL-1 analog current module
    37. const int card3 = 3; //P1-08ADL-2 analog voltage module
    38. const int card4 = 4; //P1-04THM thermocouple/strain gauge module
    39. const int temp1 = 5; //P1-04RTD module 1
    40. const int temp2 = 6; //P1-04RTD module 2
    41. const int temp3 = 7; //P1-04RTD module 3
    42.  
    43. const char P1_04THM_CONFIG[] = { 0x40, 0x01, 0x60, 0x01, 0x21, 0x09, 0x22, 0x09, 0x23, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    44. const char P1_04RTD_CONFIG[] = { 0x40, 0x03, 0x60, 0x01, 0x20, 0x01, 0x80, 0x00 };
    45.  
    46.  
    47. void setup()
    48. {
    49. Serial.begin(9600);
    50. while (!Serial){}
    51. while (!P1.init())
    52. {
    53. ; //Wait for Modules to Sign on
    54. }
    55. SD_Begin();
    56. bool THMmodstatus = P1.configureModule(P1_04THM_CONFIG, card4);
    57. bool RTD1modstatus = P1.configureModule(P1_04RTD_CONFIG, temp1);
    58. bool RTD2modstatus = P1.configureModule(P1_04RTD_CONFIG, temp2);
    59. bool RTD3modstatus = P1.configureModule(P1_04RTD_CONFIG, temp3);
    60.  
    61. }
    62. void loop()
    63. {
    64. while(Serial.available())
    65. {
    66. String teststr = Serial.readString(); //read until timeout
    67. teststr.trim(); // remove any \r \n whitespace at the end of the String
    68. if (teststr == "ON")
    69. {
    70. XV791_Open = true;
    71. }
    72. else if (teststr == "OFF")
    73. {
    74. XV791_Open = false;
    75. }
    76.  
    77. }
    78.  
    79. //****************************************************//
    80. // Get the sensor data
    81. //
    82. //****************************************************//
    83. Sensor_input();
    84. // Comment Digital Output when Testing TEST SV
    85. Digital_output();
    86. //Test_SV();
    87. SD_Card_Data();
    88. Serial_Print_Test();
    89. //send_backet(TT711, TT712, TT721, TT722, TT761, TT791, TT792, PT711, PT791, TT793, TT794, FT791VFR, FT791MFR, VG781);
    90. delay(5000);
    91. }
    92.  
    93. //****************************************************//
    94. // Analog Inputs
    95. // 0 - 20 mA Card
    96. //
    97. //****************************************************//
    98.  
    99. float mapFloat(float x, float inMin, float inMax, float outMin, float outMax)
    100. {
    101. return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
    102. }
    103.  
    104. void Sensor_input()
    105. {
    106. float AI_1_1_Count = map((P1.readAnalog(card2, 1)-1638.4), 0, 6552.6, 400, 2000) / 100.0; //analog current output
    107. VG781 = mapFloat(AI_1_1_Count, 4, 20, 0.01, 100); //in mTorr
    108. // flowmeter is 0-5V
    109. float AI_2_1_Count = mapFloat((P1.readAnalog(card3, 1)), 0, 4095.5, 0, 5.0);//analog voltage output
    110. FT791MFR = mapFloat(AI_2_1_Count, 0, 5.0, 0, 0.37); //in g/s
    111. FT791VFR = mapFloat(FT791MFR, 0, 0.37, 0, 250); //in SLPM
    112.  
    113.  
    114.  
    115. PT711 = P1.readTemperature(card4, 1);
    116. PT791 = P1.readTemperature(card4, 2);
    117.  
    118.  
    119.  
    120.  
    121.  
    122. //****************************************************//
    123. // Temperature Sensors
    124. // Convert Fahrenheit to Kelvin
    125. //
    126. //****************************************************//
    127.  
    128.  
    129. TT711 = ((P1.readTemperature(temp1, 1))) + 273.15; //TT711, PT111
    130. TT712 = ((P1.readTemperature(temp1, 2))) + 273.15; //TT712, PT111
    131.  
    132. TT721 = ((P1.readTemperature(temp1, 3))) + 273.15; //TT721, PT111
    133.  
    134. TT722 = ((P1.readTemperature(temp2, 1))) + 273.15; //TT722, PT111
    135.  
    136. TT761 = ((P1.readTemperature(temp2, 2))) + 273.15; //TT761, PT111
    137.  
    138. TT791 = ((P1.readTemperature(temp2, 3))) + 273.15; //TT791, PT111
    139.  
    140. TT792 = ((P1.readTemperature(temp3, 1))) + 273.15; //TT792, PT111
    141.  
    142. TT793 = ((P1.readTemperature(temp3, 2))) + 273.15; //TT793, PT100
    143.  
    144. TT794 = ((P1.readTemperature(temp3, 3))) + 273.15; //TT794, PT100
    145.  
    146. }
    147.  
    148.  
    149. //****************************************************//
    150. // Solenoid Valve Actions
    151. //
    152. //****************************************************//
    153.  
    154. void Digital_output()
    155. {
    156. if (XV791_Open == true)
    157. {
    158. XV791 = true;
    159. P1.writeDiscrete(HIGH, card1, 1); //Turn slot 1 channel 1 on
    160. }
    161. else
    162. {
    163. XV791 = false;
    164. P1.writeDiscrete(LOW, card1, 1); //Turn slot 1 channel 1 off
    165. }
    166. }
    167.  
    168. //****************************************************//
    169. // Save data to the SD card
    170. //
    171. //****************************************************//
    172.  
    173. bool SD_Begin(void)
    174. {
    175. Serial.print("Initializing SD card...");
    176. if (!SD.begin(chipSelect)) {
    177. Serial.println("Card failed, or not present");
    178. return(0);
    179. }
    180. else {
    181. Serial.println("card initialized.");
    182. return(1);
    183. }
    184. }
    185. void SD_Card_Data()
    186. {
    187. String dataString = "";
    188. dataString += String(TT711);
    189. dataString += ","; dataString += String(TT712);
    190. dataString += ","; dataString += String(TT721);
    191. dataString += ","; dataString += String(TT722);
    192. dataString += ","; dataString += String(TT761);
    193. dataString += ","; dataString += String(TT791);
    194. dataString += ","; dataString += String(TT792);
    195. dataString += ","; dataString += String(PT711);
    196. dataString += ","; dataString += String(PT791);
    197. dataString += ","; dataString += String(TT793);
    198. dataString += ","; dataString += String(TT794);
    199. dataString += ","; dataString += String(FT791VFR);
    200. dataString += ","; dataString += String(FT791MFR);
    201. dataString += ","; dataString += String(VG781);
    202. dataString += ","; dataString += String(XV791);
    203. File dataFile = SD.open("datalog.csv", FILE_WRITE);
    204. // if the file is available, write to it:
    205. if (dataFile)
    206. {
    207. dataFile.println(dataString);
    208. dataFile.close();
    209. // print to the serial port too:
    210. //Serial.println(dataString);
    211. }
    212. // if the file isn't open, pop up an error:
    213. else
    214. {
    215. //Serial.println("error opening datalog.csv");
    216. SD_Begin();
    217. }
    218. }
    219. //****************************************************//
    220. // Communication with Visualizer App
    221. //
    222. //****************************************************//
    223.  
    224. void send_backet(float RTD1_1, float RTD1_2, float RTD1_3, float RTD1_4, float RTD2_1, float RTD2_2, float RTD2_3, float PT1, float PT2, float RTD2_4, float RTD3_1, float VFRval, float MFRval, float VG)
    225. {
    226. String backet = "@" + String(RTD1_1) + "," + String(RTD1_2) + "," + String(RTD1_3) + "," + String(RTD1_4) + "," + String(RTD2_1) + "," + String(RTD2_2) + "," + String(RTD2_3) + "," + String(PT1) + "," + String(PT2) + "," + String(RTD2_4) + "," + String(RTD3_1) + String(VFRval) + "," + String(MFRval) + "," + String(VG) + "%";
    227.  
    228. int len = backet.length();
    229. int count = 0;
    230. for (int i = 0; i < len; i++)
    231. {
    232. if (backet[i] == '@')
    233. {
    234. count++;
    235. }
    236. }
    237. if (count == 1)
    238. {
    239. Serial.print(backet);
    240. }
    241. }
    242.  
    243. void Serial_Print_Test()
    244. {
    245. Serial.print("TT-711: ");
    246. Serial.println(TT711, 2);
    247. Serial.print("TT-722: ");
    248. Serial.println(TT722, 2);
    249. Serial.print("TT-794: ");
    250. Serial.println(TT794, 2);
    251. Serial.print("TT-721: ");
    252. Serial.println(TT721, 2);
    253. Serial.print("TT-712: ");
    254. Serial.println(TT712, 2);
    255. Serial.print("VG-781: ");
    256. Serial.println(VG781, 2);
    257. Serial.print("PT-791: ");
    258. Serial.println(PT791, 8);
    259. Serial.print("PT-711: ");
    260. Serial.println(PT711, 8);
    261. Serial.println("THMmodstatus: ");
    262. Serial.println(THMmodstatus,2);
    263. Serial.println("RTD1modstatus: ");
    264. Serial.println(RTD1modstatus,2);
    265.  
    266.  
    267. }
    268.  
    269. void Test_SV()
    270. {
    271. P1.writeDiscrete(HIGH,card1,1); //Turn slot 1 channel 1 on
    272. delay(5000); //wait 5 second
    273. P1.writeDiscrete(LOW,card1,1); //Turn slot 1 channel 1 off
    274. delay(5000); //wait 5 second
    275. }

    When the modules initialize they print this:

    TT-711: 273.15

    TT-722: 273.15

    TT-794: 273.15

    TT-721: 273.15

    TT-712: 273.15

    VG-781: -24.93

    PT-791: 0.00000000

    PT-711: 0.00000000

    THMmodstatus:

    0

    RTD1modstatus:

    0

     

    When I connect RTD (PT100) TT-711 and TT-721, as well as a thermocouple on PT-711 only to see if there is any mV reading I get the following:

    TT-711: 295.10

    TT-722: 73.15

    TT-794: 73.15

    TT-721: 293.41

    TT-712: 73.15

    VG-781: -24.93

    PT-791: 0.12799999

    PT-711: 0.00000000

    THMmodstatus:

    0

    RTD1modstatus:

    0

     

    Expand Post
    • FACTS_AdamC (AutomationDirect)

      I ran your code on a comparable setup on my desk and was seeing proper readings on the P1-04THM.

       

      Could you try the following:

      1. Connect a wire from A0 on the header to channel 1+ of the THM
      2. Connect a wire from GND on the header to channel 1- of the THM
      3. Replace the contents of your loop() with the following
      1. void loop()
      2. {
      3. analogWrite(A0, 2);
      4. Serial.println(P1.readTemperature(card4, 1),8);
      5. delay(1000);
      6. }

      On my setup, this is printing out ~0.027V to the monitor.

      Expand Post