<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>YAPS Part Seven - Prototyping of Arduino Interface</title><link>/members-area/personalblogs/b/blog/posts/yaps-part-seven---prototyping-of-arduino-interface</link><description>EDITS: 6/11/19 - Fixed broken links; Added link to Part Eight. I&amp;#39;m going with an Arduino interface to display voltage, current, power and temperatures. In the first version this will be display only - controls for setting voltage and c...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: YAPS Part Seven - Prototyping of Arduino Interface</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/yaps-part-seven---prototyping-of-arduino-interface</link><pubDate>Fri, 07 Jun 2019 17:33:12 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:38448b26-f6b8-419a-8dac-f14ce32efa94</guid><dc:creator>shabaz</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi Andrew,&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;This is great seeing the 4D systems display/controller and the code.&lt;/p&gt;&lt;p&gt;The 4D systems stuff looks fantastic, I saw some of their displays at an exhibition, and the latest generation ones look very cool.&lt;/p&gt;&lt;p&gt;I recently tried a cheap ebay display, while it works, it isn&amp;#39;t a top-quality screen and suffers from poor viewing angles.&lt;/p&gt;&lt;p&gt;Also, it is very cool that you&amp;#39;re using the Steinhart-Hart equation to get accurate temperature conversions. &lt;/p&gt;&lt;p&gt;It&amp;#39;s nice seeing designs with such a screen, since there is a lot of information that can be gleaned from your sensors, and it&amp;#39;s fun trying new things like this, deciding how the UI should look, and what functionality to have!&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=7223&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: YAPS Part Seven - Prototyping of Arduino Interface</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/yaps-part-seven---prototyping-of-arduino-interface</link><pubDate>Fri, 07 Jun 2019 10:09:48 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:38448b26-f6b8-419a-8dac-f14ce32efa94</guid><dc:creator>Andrew J</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Now we&amp;#39;re cooking on gas!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I&amp;#39;ve made a few updates to the code to improve accuracy.&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Firstly, the Voltage, Current and Power - the mistake I made initially with the power reading was ignoring the 10mW LSB value the INA260 holds - accounting for that brings it into expectation.&amp;nbsp; All values have some LSB size to take account of:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Voltage: 1.25mV&lt;/li&gt;&lt;li&gt;Current: 1.25mA&lt;/li&gt;&lt;li&gt;Power: 10mW&amp;nbsp; I suppose I could just take the Voltage and Current values and work out the power myself, save a read etc.&amp;nbsp; &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span&gt;[View:/resized-image/__size/620x312/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-38448b26-f6b8-419a-8dac-f14ce32efa94/2313.contentimage_5F00_191033.jpg:620:312]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The Fluke is measuring Voltage; the Extech Current.&amp;nbsp; What we are seeing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Fluke: 5.4840V&lt;/li&gt;&lt;li&gt;Extech: 11.44mA&lt;/li&gt;&lt;li&gt;4Duino: 5.488V; 0.009mA; 0.050mW reported (against a P=VI calculation of 0.049mW)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I&amp;#39;d say that was pretty good!&amp;nbsp; 2mA of current off.&amp;nbsp; The datasheet for the INA260 states it has a 5mA offset maximum and a current sense gain error of 0.2%typical to 0.5%max.&amp;nbsp; That wouldn&amp;#39;t count for it all but I&amp;#39;m also measuring that current through 2&amp;quot; of hookup wire.&amp;nbsp; It&amp;#39;s accurate enough.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Secondly, the temperature readings.&amp;nbsp; I was right in that the culprit in the inaccuracy was the nominal 5V Vin on the 4Duino.&amp;nbsp; That&amp;#39;s used as a reference in the analog reading conversion: if it isn&amp;#39;t precisely 5V then the conversion is off.&amp;nbsp; Even providing it with a regulated 5V supply isn&amp;#39;t going to give that level of accuracy and it will always fluctuate somewhat.&amp;nbsp; In fact, the voltage supplied is a few 10&amp;#39;s of mV lower than 5V causing the analog reading to go high - hence the higher temperature readings displayed.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Here&amp;#39;s what I show now:&lt;/p&gt;&lt;p&gt;&lt;span&gt;[View:/resized-image/__size/620x353/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-38448b26-f6b8-419a-8dac-f14ce32efa94/8512.contentimage_5F00_191034.jpg:620:353]&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Hive is showing: 22.6C&lt;/li&gt;&lt;li&gt;Clock is showing: 22.1C&lt;/li&gt;&lt;li&gt;4Duino is showing: 22.26C; 22.78C; 22.33C&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I can definitely live with that accuracy!&amp;nbsp; I made two changes to the code.&amp;nbsp; Firstly, when taking the analog reading I also took a Vcc reading using the ATMega32U4 internal voltage reference of 1.1V.&amp;nbsp; I then used that reference to accurately convert the analog reading into a voltage reading.&amp;nbsp; This bypasses the conversion using the 5V &amp;#39;perfect&amp;#39; supply.&amp;nbsp; Secondly, although minor, I changed the Steinhart Hart calculation to use a more accurate equation incorporating coefficients from the &lt;a class="jive-link-external-small" href="https://media.digikey.com/pdf/Data%20Sheets/Ametherm%20PDFs/PANE_103395-410_Spec.pdf" rel="nofollow ugc noopener" target="_blank"&gt;datasheet&lt;/a&gt;.&amp;nbsp; I&amp;#39;ve only used those applicable to a range of 50.5C to 103C and could squeeze a little more accuracy by including the range from -2C to 50.5C but I don&amp;#39;t think that&amp;#39;s necessary: I think a fraction of a degree discrepancy is accurate enough, will always be subject to the actual resistances of the Thermistors (which I can&amp;#39;t be bothered to calibrate) and it&amp;#39;s impossible to say which of the 3 Thermistors, Hive and Clock are the correct reading in any case.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;You&amp;#39;ll also notice that the display shows a Control Temperature: this is actually a specific resistance taken from the datasheet and pushed through the calculation to make sure it was accurate - the answer for 8766Ohms should be, and is, 28C.&amp;nbsp; As an aside, Excel calculated it out at 26.somethingC which led me down a lot of pointless cross-checking.&amp;nbsp; There&amp;#39;s something screwy within its calculation I&amp;#39;m sure - possibly the logarithm function.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I&amp;#39;m really happy with that.&amp;nbsp; The final display I want to incorporate graphics and the like but I now have something to test the build against.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Latest Code&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;/*&amp;nbsp; Simple prototype for the 4Duino using three thermistors and an INA260.&lt;/p&gt;&lt;p&gt; *&amp;nbsp; These form part of the monitoring of the final build and this code should form the basis of a graphical build&lt;/p&gt;&lt;p&gt; *&amp;nbsp; as part of the final version.&lt;/p&gt;&lt;p&gt; *&amp;nbsp; Prototype is using simple print/println commands&lt;/p&gt;&lt;p&gt; */&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;// For SDA/SCL connections&lt;/p&gt;&lt;p&gt;#include &amp;lt;Wire.h&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;// Picaso display libraries&lt;/p&gt;&lt;p&gt;#include &amp;lt;Picaso_Const4D.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include &amp;lt;Picaso_Serial_4DLib.h&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;#define DisplaySerial Serial1&lt;/p&gt;&lt;p&gt;Picaso_Serial_4DLib Display(&amp;amp;DisplaySerial);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;// Thermistors - references in schematic&lt;/p&gt;&lt;p&gt;#define TH1 A0 // analog pin connected&lt;/p&gt;&lt;p&gt;#define TH2 A1 // analog pin connected&lt;/p&gt;&lt;p&gt;#define TH3 A2 // analog pin connected&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;// Resistors - measured with DMM - references in schematic&lt;/p&gt;&lt;p&gt;#define R1 10065&lt;/p&gt;&lt;p&gt;#define R2 9948&lt;/p&gt;&lt;p&gt;#define R3 9909&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;#define THERMISTORNOMINAL 10000.0 // resistance at 25C&lt;/p&gt;&lt;p&gt;#define TEMPERATURENOMINAL 25.0&amp;nbsp;&amp;nbsp; // degrees centigrade&lt;/p&gt;&lt;p&gt;#define CONTROLRESISTANCE 8766&amp;nbsp;&amp;nbsp;&amp;nbsp; // This should calculate a temperature of 28C&lt;/p&gt;&lt;p&gt;#define NUMSAMPLES 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Improve calculation efficiency by averaging reads over a number of samples&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void setup() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; setupLCD();&lt;/p&gt;&lt;p&gt;&amp;nbsp; setupINA260();&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void setupLCD() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.Callback4D = mycallback;&amp;nbsp; // For handling errors&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.TimeLimit4D = 5000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 5secs timeout on all commands&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplaySerial.begin(200000);&lt;/p&gt;&lt;p&gt;&amp;nbsp; delay(5000);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // let the display startup&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.gfx_ScreenMode(LANDSCAPE);&amp;nbsp; &lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void setupINA260() {&lt;/p&gt;&lt;p&gt; // write to the INA260: Address:Register:High Byte:Low Byte&lt;/p&gt;&lt;p&gt; // See datasheet for values &lt;/p&gt;&lt;p&gt; Wire.begin(); &lt;/p&gt;&lt;p&gt; Wire.beginTransmission(0x40); //address set by A1 and A0 pins on INA260&lt;/p&gt;&lt;p&gt; Wire.write(0x00);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // config register&lt;/p&gt;&lt;p&gt; Wire.write(0x61);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // high byte -&amp;gt; take 1 average&lt;/p&gt;&lt;p&gt; //Wire.write(0x65);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // high byte -&amp;gt; take 4 averages&lt;/p&gt;&lt;p&gt; Wire.write(0xb7);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // low byte -&amp;gt; conversion time for voltage and current = 4.156 ms &lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // (average out the data for low noise), and operate in continous mode &lt;/p&gt;&lt;p&gt; Wire.endTransmission(); &lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void loop() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Clear the screen and display the temperature from each thermistor in turn.&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Followed by V,I,P from INA260&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; // The 10 second delay is to give a chance to read it.&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.gfx_Cls();&lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplayTemperature(TH1, R1);&lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplayTemperature(TH2, R2);&lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplayTemperature(TH3, R3);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(&amp;quot;Control Temperature&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Control Resistance: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(CONTROLRESISTANCE);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Temperature(CONTROLRESISTANCE); // Lets check we see 28C with the calculation&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplayVoltage();&lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplayCurrent();&lt;/p&gt;&lt;p&gt;&amp;nbsp; DisplayPower();&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; delay(10000);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt; * Obtain the actual Vcc value of the 4Duino from an internal reference source.&lt;/p&gt;&lt;p&gt; * The nominal 5V Vin can fluctuate a lot and affect analog read accuracy.&lt;/p&gt;&lt;p&gt; */&lt;/p&gt;&lt;p&gt;long readVCC() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; long result;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Read 1.1V reference against AVcc&lt;/p&gt;&lt;p&gt;&amp;nbsp; ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);&lt;/p&gt;&lt;p&gt;&amp;nbsp; delay(2); // Wait for Vref to settle&lt;/p&gt;&lt;p&gt;&amp;nbsp; ADCSRA |= _BV(ADSC); // Convert&lt;/p&gt;&lt;p&gt;&amp;nbsp; while (bit_is_set(ADCSRA, ADSC));&lt;/p&gt;&lt;p&gt;&amp;nbsp; result = ADCL;&lt;/p&gt;&lt;p&gt;&amp;nbsp; result |= ADCH &amp;lt;&amp;lt; 8;&lt;/p&gt;&lt;p&gt;&amp;nbsp; result = 1126400L / result; // Calculate Vcc (in mV); 1126400 = 1.1*1024*1000&lt;/p&gt;&lt;p&gt;&amp;nbsp; return result;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt;&amp;nbsp; Return an averaged reading from the Thermistor voltage divider&lt;/p&gt;&lt;p&gt;*/&lt;/p&gt;&lt;p&gt;float ReadThermistor(int pin) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; uint8_t i;&lt;/p&gt;&lt;p&gt;&amp;nbsp; float average;&lt;/p&gt;&lt;p&gt;&amp;nbsp; float samples[NUMSAMPLES];&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; for (i = 0; i &amp;lt; NUMSAMPLES; i++) {&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int value = analogRead(pin);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; float supply = readVCC() / 1000.0; // obtain vcc at time of read&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; float valueCorrected = supply / 5 * value; // improve the accuracy of the analog reading&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; samples[i] = valueCorrected;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delay(10); // spread readings out otherwise they are likely to be the same value or very close&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; average = 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; for (i = 0; i &amp;lt; NUMSAMPLES; i++) {&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; average += samples[i];&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp; return average / NUMSAMPLES;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt;&amp;nbsp; Displays values associated with the passed Thermistor and series resistance&lt;/p&gt;&lt;p&gt;*/&lt;/p&gt;&lt;p&gt;void DisplayTemperature(int thermistor, long seriesResistor) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; float reading;&lt;/p&gt;&lt;p&gt;&amp;nbsp; float resistance;&lt;/p&gt;&lt;p&gt;&amp;nbsp; float vOut;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Obtain reading from thermistor&lt;/p&gt;&lt;p&gt;&amp;nbsp; reading = ReadThermistor(thermistor);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Analog reading TH&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(thermistor - 13);&amp;nbsp; // Analog Pins seem to have an int value starting at 14.&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(reading);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Convert the value to a resistance at the current temperature&lt;/p&gt;&lt;p&gt;&amp;nbsp; resistance = seriesResistor * (1024.0 / reading - 1.0);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Thermistor resistance: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(resistance);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Calculate and display temperature&lt;/p&gt;&lt;p&gt;&amp;nbsp; Temperature(resistance);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt;&amp;nbsp; Calculate the temperature based on the Steinhart-Hart equation.&lt;/p&gt;&lt;p&gt;&amp;nbsp; Coefficients are from the datasheet&lt;/p&gt;&lt;p&gt;&amp;nbsp; An alternative would be to hold a table of resistances/temperatures from the datasheet.&lt;/p&gt;&lt;p&gt;&amp;nbsp; Must consider memory usage.&lt;/p&gt;&lt;p&gt;*/&lt;/p&gt;&lt;p&gt;void Temperature(float r2) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; float temperature;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double coeffA = 3.354016e-03;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double coeffB = 2.541522e-04;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double coeffC = 3.730922e-06;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double coeffD = -7.881561e-08;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double logR2 = 0.0;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; logR2 = log(r2/THERMISTORNOMINAL);&lt;/p&gt;&lt;p&gt;&amp;nbsp; temperature = (1.0 / (coeffA + coeffB*logR2 + coeffC*logR2*logR2 + coeffD*logR2*logR2*logR2));&lt;/p&gt;&lt;p&gt;&amp;nbsp; temperature -= 273.15;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Temperature: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(temperature);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(&amp;quot; *C&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(&amp;quot;&amp;quot;);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void DisplayVoltage() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; double dVoltage = 0.0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; // ask for voltage readings&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.beginTransmission(0x40); // Address&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.write(0x02);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Bus Voltage Register&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.endTransmission();&lt;/p&gt;&lt;p&gt;&amp;nbsp; dVoltage = ReadData(1.25);&amp;nbsp;&amp;nbsp;&amp;nbsp; // Voltage is accurate to 1.25V&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Display&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Voltage: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(dVoltage, 3);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(&amp;quot;V&amp;quot;);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void DisplayCurrent() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; double dCurrent = 0.0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; // ask for current readings&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.beginTransmission(0x40); // Address&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.write(0x01);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Bus Voltage Register&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.endTransmission();&lt;/p&gt;&lt;p&gt;&amp;nbsp; dCurrent = ReadData(1.25);&amp;nbsp;&amp;nbsp;&amp;nbsp; // Current is accurate to 1.25mA&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Display&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Current: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(dCurrent, 3);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(&amp;quot;A&amp;quot;);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;void DisplayPower() {&lt;/p&gt;&lt;p&gt;&amp;nbsp; double dPower = 0.0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; // ask for power readings&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.beginTransmission(0x40); // Address&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.write(0x03);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Bus Voltage Register&lt;/p&gt;&lt;p&gt;&amp;nbsp; Wire.endTransmission();&lt;/p&gt;&lt;p&gt;&amp;nbsp; dPower = ReadData(10.0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Power is accurate to 10mW&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; // Display&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(&amp;quot;Power: &amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.print(dPower, 3);&lt;/p&gt;&lt;p&gt;&amp;nbsp; Display.println(&amp;quot;W&amp;quot;);&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt; * Read NUMSAMPLES values from the preset register (for V, I or P) and average them.&lt;/p&gt;&lt;p&gt; * The LSB size represents the LSB size as stated in the datasheet.&lt;/p&gt;&lt;p&gt; */&lt;/p&gt;&lt;p&gt;double ReadData(float lsbSize) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; long total = 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; int value = 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double dValue = 0.0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp; total = 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; for(int i = 0; i &amp;lt; NUMSAMPLES; i++){&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Wire.requestFrom(0x40, 2); // Read two bytes&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delay(5);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (2 &amp;lt;= Wire.available()) { &lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = Wire.read();&amp;nbsp;&amp;nbsp;&amp;nbsp; // receive high byte (overwrites previous reading)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = value &amp;lt;&amp;lt; 8;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // shift high byte to be high 8 bits&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value |= Wire.read();&amp;nbsp;&amp;nbsp; // receive low byte as lower 8 bits&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total += value;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Turn into high precision, average them and convert to result&lt;/p&gt;&lt;p&gt;&amp;nbsp; dValue = total;&lt;/p&gt;&lt;p&gt;&amp;nbsp; dValue = ((dValue * lsbSize) / 5.000) / 1000.000;&lt;/p&gt;&lt;p&gt;&amp;nbsp; return dValue;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt; * Simple error handling: flash an LED.&lt;/p&gt;&lt;p&gt; */&lt;/p&gt;&lt;p&gt;void mycallback(int ErrCode, unsigned char Errorbyte)&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; // Pin 13 has an LED connected on most Arduino boards. Just give it a name&lt;/p&gt;&lt;p&gt;&amp;nbsp; int led = 13;&lt;/p&gt;&lt;p&gt;&amp;nbsp; pinMode(led, OUTPUT);&lt;/p&gt;&lt;p&gt;&amp;nbsp; while(1)&lt;/p&gt;&lt;p&gt;&amp;nbsp; {&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; digitalWrite(led, HIGH);&amp;nbsp; // turn the LED on (HIGH is the voltage level)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delay(1000);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wait for 200 ms&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; digitalWrite(led, LOW);&amp;nbsp;&amp;nbsp; // turn the LED off by making the voltage LOW&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delay(1000);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // wait for 200 ms&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=7223&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: YAPS Part Seven - Prototyping of Arduino Interface</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/yaps-part-seven---prototyping-of-arduino-interface</link><pubDate>Thu, 06 Jun 2019 19:44:56 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:38448b26-f6b8-419a-8dac-f14ce32efa94</guid><dc:creator>three-phase</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;This is a very interesting series to follow along with, I look forward to seeing you complete the project.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Kind regards.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=7223&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>