<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Provide data from .c file to .py file VS Code - matplotlib.pyplot</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93069/provide-data-from-c-file-to-py-file-vs-code---matplotlib-pyplot</link><description>Hello, 
 
 I got saadc example on my nrf5340 dk running and now I would like to plot the incoming serial data. 
 saadc code example: saadc.zip 
 changed the way I got adviced in / nrfx_saadc---buildconf-error-ppi_chen-dppic_chen 
 My approach is using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 24 Oct 2022 09:05:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93069/provide-data-from-c-file-to-py-file-vs-code---matplotlib-pyplot" /><item><title>RE: Provide data from .c file to .py file VS Code - matplotlib.pyplot</title><link>https://devzone.nordicsemi.com/thread/392069?ContentTypeID=1</link><pubDate>Mon, 24 Oct 2022 09:05:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffb98637-0909-4f63-9412-a3b76b16fd78</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Christoph,&lt;/p&gt;
&lt;p&gt;I am using a very simple setup to print numbers using printk() function. The main() code is as here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;


void main(void)
{
	int i=0, res=0;
	while(1)
	{
		res = i * i;
		printk(&amp;quot;%d\t%d\n&amp;quot;, i, res);
		i++;
		k_msleep(1000);
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can use nRF terminal, or any other teriminal like PuTTY (using the correct baudrate configurations). In my case it is 115200.&lt;/p&gt;
&lt;p&gt;After you verify you that you can see output in the terminal, then you can disconnect terminal and just run your .py code.&lt;/p&gt;
&lt;p&gt;It should fetch lines from COM port and print data accordingly. Please modify as per your needs.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Provide data from .c file to .py file VS Code - matplotlib.pyplot</title><link>https://devzone.nordicsemi.com/thread/391983?ContentTypeID=1</link><pubDate>Sun, 23 Oct 2022 06:29:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d65b1bc-9033-4fc4-b402-1052547544d8</guid><dc:creator>ChrtistophAT</dc:creator><description>&lt;p&gt;Thank you for your help &lt;a href="https://devzone.nordicsemi.com/members/naeem-maroof"&gt;Naeem Maroof&lt;/a&gt;&amp;nbsp;!!&lt;/p&gt;
&lt;p&gt;Can you provide your main.c code to discover how build up simple serial communication from DK to computer. The nrf terminal and simple terminal are confusig me a bit.&lt;/p&gt;
&lt;p&gt;Many thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Provide data from .c file to .py file VS Code - matplotlib.pyplot</title><link>https://devzone.nordicsemi.com/thread/391962?ContentTypeID=1</link><pubDate>Fri, 21 Oct 2022 20:51:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9f311d1-c7ad-4814-beff-e2c357fce495</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Dear Christoph,&lt;/p&gt;
&lt;p&gt;Thank you for contacting DevZone at NordicSemi.&lt;/p&gt;
&lt;p&gt;As per your query, you are using SAADC example for nRF5340-DK and want to plot the incoming serial data using Python.&lt;/p&gt;
&lt;p&gt;The code you have provided is not building and is causing so many errors. Nonetheless, I worked on to solve your basic problem, that is plotting incoming data.&lt;/p&gt;
&lt;p&gt;So, I configured my DK to send (x,y) data over UART to the computer. In this case, I am sending square of a number (y = x^2) after every second.&lt;/p&gt;
&lt;p&gt;Using online resources, I generated python code which would read from the serial port and then plot in real-time. Please note that the code might not be accurate, and also may not suffice your needs. However, you can use it as guideline and built your own code from it. Other solutions, using commercial data loggers, might also be possible.&lt;/p&gt;
&lt;p&gt;So basically,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;I am configuring the COM port (in my case its COM5) and the baudrate (as per DK baudrate)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;Then, within the animate() function, I am reading a line from the serial port&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;Then splitting the line data and making a list of items from it &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;As I know that I am sending (x,y) data, I am expecting 2 items. If there are two items in the list then I extract integer values and put them in x and y list&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;Then we print the (x,y) data on the plot&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Example run of code is shown in the attached image.&amp;nbsp;Python code is also attached.&amp;nbsp;Hope it will be helpful.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/example_5F00_run_5F00_serial_5F00_data.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/main.py"&gt;devzone.nordicsemi.com/.../main.py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;With regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>