meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
arduino:code_collection [2025/03/22 19:49] – [TON] vamsanarduino:code_collection [2025/03/22 22:54] (current) – [Float to char[]] vamsan
Line 15: Line 15:
     // ...     // ...
   }     }  
 +</code>
 +
 +==== check serial monitor ====
 +<code c>
 +
 +  // code in setup()
 +  Serial.begin(9600);
 +  
 +  while (!Serial) {
 +    ; // wait for serial port to connect. Needed for native USB port only
 +  }
 +  Serial.println("Serial monitor OK");
 +</code>
 +===== Converting code collection =====
 +==== Float to char[] ====
 +<code c>
 +// lib init (optional)
 +#include "avr/dtostrf.h"
 +// converting 
 +float a;
 +char sendValue[10];
 +dtostrf (a, 10, 8, sendValue); // float_value, min_width, num_digits_after_decimal, where_to_store_string
 +
 +</code>
 +
 +==== Int to char[] ====
 +<code c>
 +int a;
 +char sendValue[10];
 +itoa (i,sendValue,10); // int value, char * str, int base
 +// base:  Numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary
 +
 +</code>
 +==== String to char[] ====
 +<code c>
 +
 +char place[20];
 +strcpy(place,"Home");
 +
 </code> </code>
 ===== Modbus code collection ===== ===== Modbus code collection =====