<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Record bipolar analog AC current signal - Raspberry Pi				            </title>
            <link>https://www.tweaking4all.com/forum/raspberry-pi/record-bipolar-analog-ac-current-signal/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 17 Mar 2026 00:15:23 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Record bipolar analog AC current signal</title>
                        <link>https://www.tweaking4all.com/forum/raspberry-pi/record-bipolar-analog-ac-current-signal/#post-2890</link>
                        <pubDate>Wed, 09 Dec 2020 11:50:13 +0000</pubDate>
                        <description><![CDATA[I never dived into current measuring, so I am not sure if this is relevant or not.First thing I thought was measuring current (A) versus voltage (V). But I suppose both are sinus shaped.
Th...]]></description>
                        <content:encoded><![CDATA[<p>I never dived into current measuring, so I am not sure if this is relevant or not.<br />First thing I thought was measuring current (A) versus voltage (V). But I suppose both are sinus shaped.</p>
<p>The next though I had is that the sensor's purpose was to measure the load (A) on a wire, so maybe the sensor is actually making it a flat line already?<br />I honestly have no clue, this is just me guessing.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/raspberry-pi/">Raspberry Pi</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/raspberry-pi/record-bipolar-analog-ac-current-signal/#post-2890</guid>
                    </item>
				                    <item>
                        <title>Record bipolar analog AC current signal</title>
                        <link>https://www.tweaking4all.com/forum/raspberry-pi/record-bipolar-analog-ac-current-signal/#post-2888</link>
                        <pubDate>Wed, 09 Dec 2020 10:41:30 +0000</pubDate>
                        <description><![CDATA[Hi, I want to record the AC current time stamp data into my RaspberryPi from current sensor (WCS1600) via an ADC(ADS1015) that is being supplied to my mobile.
Herewith I have attached a sch...]]></description>
                        <content:encoded><![CDATA[<p>Hi, I want to record the AC current time stamp data into my RaspberryPi from current sensor (WCS1600) via an ADC(ADS1015) that is being supplied to my mobile.</p>
<p>Herewith I have attached a schematic diagram of the setup.</p>
130
<p> </p>
<p><span>For the pyhton codes, I have referred following link </span><a href="https://github.com/OpenLabTools/RPi_ADS1115/blob/master/code/continuous_read_adc.py" rel="nofollow noreferrer">https://github.com/OpenLabTools/RPi_ADS1115/blob/master/code/continuous_read_adc.py</a><span> with some modification. It is mentioned below:</span></p>
<p> </p>
<pre class="lang-py s-code-block hljs python"><code><span class="hljs-keyword">from</span> Adafruit_ADS1x15 <span class="hljs-keyword">import</span> ADS1x15
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt


pga = <span class="hljs-number">1</span>                 <span class="hljs-comment"># Set full-scale range of programable gain amplifier </span>
ADS1015 = <span class="hljs-number">0x00</span>          <span class="hljs-comment"># Specify that the device being used is ADS1015</span>
adc = ADS1x15(ic=ADS1015)   <span class="hljs-comment"># Create instance of the class ADS1x15 called adc</span>

<span class="hljs-comment"># Function to print sampled values to the terminal</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">logdata</span>():</span>

    <span class="hljs-built_in">print</span> <span class="hljs-string">"sps value should be one of: 128, 250, 490, 920, 1600, 2400, 3300, otherwise the value will default to 1600"</span>
        
    frequency = <span class="hljs-number">1000</span>                    <span class="hljs-comment"># Data rate in Hz</span>
    sps = <span class="hljs-number">3300</span>                              <span class="hljs-comment"># maximum sps value for ADS1015 </span>
    time1 = <span class="hljs-number">10</span>                          <span class="hljs-comment"># how long to sample in seconds</span>
    
    period = <span class="hljs-number">1.0</span> / frequency        <span class="hljs-comment"># Calculate sampling period</span>

    datapoints = <span class="hljs-built_in">int</span>(time1*frequency)   <span class="hljs-comment"># Datapoints is the total number of samples to take, which must be an integer</span>
    dataarray=np.zeros()  <span class="hljs-comment"># Create numpy array to store value and time at which samples are taken</span>

    adc.start_adc(<span class="hljs-number">0</span>, pga, sps)          <span class="hljs-comment"># Begin continuous conversion on input A0</span>
    
    startTime=time.time()               <span class="hljs-comment"># Time of first sample</span>
    t1=startTime                    <span class="hljs-comment"># T1 is last sample time</span>
    t2=t1                       <span class="hljs-comment"># T2 is current time</span>

    V_dd = <span class="hljs-number">3.3</span>                                      <span class="hljs-comment"># ADS1015 is powered with 3.3V from RPi</span>
    n    = <span class="hljs-number">12</span>                                       <span class="hljs-comment"># No. of bits in ADS1015</span>
    senstivity = <span class="hljs-number">0.022</span>                              <span class="hljs-comment"># Sensitivity of WCS1600 in V/A</span>
    
    <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span> (<span class="hljs-number">0</span>,datapoints) :         <span class="hljs-comment"># Loop in which data is recorded</span>
            
            dataarray = time.time()-startTime                            <span class="hljs-comment"># Store the sample time in the numpy array            </span>
            dataarray= ((adc.get_last_result())*(V_dd)/(<span class="hljs-number">2</span>**n))/ senstivity   <span class="hljs-comment"># Get the result in Amperes of the last conversion from ADS1015 and store in numpy array</span>


            <span class="hljs-keyword">while</span> (t2-t1 &lt; period) :        <span class="hljs-comment"># Check if t2-t1 is less then sample period, if it is then update t2</span>
                t2=time.time()          <span class="hljs-comment"># and check again       </span>
            t1+=period              <span class="hljs-comment"># Update last sample time by the sampling period</span>
                    
    <span class="hljs-keyword">return</span> (dataarray)

dataSamples = logdata()                       <span class="hljs-comment"># Call function to log data</span>
    
<span class="hljs-comment"># Plot time data</span>
TIME      = dataarray[:,]
CURRENT   = dataarray[:,]
plt.plot(TIME,CURRENT <span class="hljs-string">'r'</span>, linewidth=<span class="hljs-number">1</span>)
plt.xlabel(<span class="hljs-string">'Time (s)'</span>)
plt.ylabel(<span class="hljs-string">'Current (A)'</span>)</code></pre>
<p> </p>
<p>The input side the charger reads (110-220 V, 50 Hz, 0.3A).So we can expected a sinusoidal wave for the current time stamp with maximum current restricted to 0.3A.</p>
<p>However, on plotting the time vs current below graph is achieved which is obviously wrong:</p>
<p> </p>
131
<p><span>Can somebody please let me know why am I not getting sinusoidal waveform, I would be very much appreciative</span></p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/raspberry-pi/">Raspberry Pi</category>                        <dc:creator>ranjanpal</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/raspberry-pi/record-bipolar-analog-ac-current-signal/#post-2888</guid>
                    </item>
							        </channel>
        </rss>
		