کوډ ولټوئ

د اوسني اندازه کول د Allegro ACS758 اوسني سینسر په کارولو سره د SSD1306 OLED ښودنې سره د Arduino لپاره

د اوسني اندازه کول د Allegro ACS758 اوسني سینسر په کارولو سره د SSD1306 OLED ښودنې سره د Arduino لپاره

دا ټیوټوریل به تاسو ته لارښوونه وکړي چې څنګه د Allegro ACS758 د جریان سینسر په کارولو سره جریان اندازه کړئ او پایلې د SSD1306 OLED پردې باندې وښایئ. دا پروژه به د یوې سرکټ څخه د تېرېدونکي جریان لوستل او د هغه معلوماتو په OLED پردې باندې بصري ښودل شامل وي، چې د اسانه څارنې اجازه ورکوي. تاسو به زده کړئ چې څنګه اجزا وصل کړئ، کوډ ولیکئ، او پوه شئ چې هر څه څنګه یوځای کار کوي.

SSD1306 OLED display

که تاسو غواړئ چې کوډ او د هغه فعالیت پوه شئ، نو ډاډه اوسئ چې د لا زیاتو تفصیلي توضیحاتو لپاره ویډیو وګورئ (په ویډیو کې په 02:45 کې).

هارډویر تشریح شوی

د دې پروژې اصلي اجزا د Allegro ACS758 د جریان سینسر او د SSD1306 OLED پرده شامل دي. ACS758 یو هال-اثر د جریان سینسر دی چې د یو کنډکټر څخه تېرېدونکی جریان د لوړ دقت سره اندازه کوي او د دې جریان سره متناسب د تولید ولتاژ چمتو کوي. دا کولی شي تر 200A پورې جریان اداره کړي او په 3.3V یا 5V دواړو کې کار کوي.

د SSD1306 OLED پرده یوه کمپیکټه، ټیټ بریښنا پرده ده چې د I2C له لارې اړیکه نیسي. دا معمولا د Arduino پروژو کې د ادغام اسانتیا او د ګرافیک او متن د روښانه ښودلو وړتیا له امله کارول کیږي. دا اجزا یوځای د مختلفو غوښتنلیکونو کې د جریان څارنې لپاره یوه پیاوړې وسیله جوړوي.

ډیټاشیټ تفصیلات

جوړونکیAllegro Microsystems
د پرزې شمېرهACS758ECB-200U
منطق/IO ولتاژ3.3 V / 5 V
د بریښنا رسولو ولتاژ5 V
د تولید جریان (په هر چینل)200 A
د لوړ جریان (په هر چینل)200 A
د PWM فریکونسي لارښوونهN/A
د داخلولو منطق حدونه0.3 V (ټیټ)، 2.7 V (لوړ)
د ولتاژ کمښت / RDS(on) / سنتریشن0.05 V
حرارتي حدونه-40 تر 125 °C
بستهSOIC-8
یادښتونه / بڼېدوه اړخیز او یو اړخیز ماډلونه شتون لري

  • د دقیق لوستلو لپاره د ACS758 سینسر سم لوری ډاډمن کړئ.
  • که چیرې د اعظمي جریان حدونو ته نږدې کار کوئ، د ډیر تودوخې مخنیوي لپاره د تودوخې سنک وکاروئ.
  • د مستحکم عملیاتو لپاره سینسر ته د بریښنا رسول جلا کړئ.
  • د تارونو اړیکې وګورئ ترڅو د تېروونکو داخلونو مخه ونیسئ چې کیدای شي غلط لوستل رامینځته کړي.
  • د دقیق جریان اندازه کولو ډاډ ترلاسه کولو لپاره د سینسر تولید کیلیبریټ کړئ.

د تارونو لارښوونې

Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64
Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64

د Allegro ACS758 د جریان سینسر او SSD1306 OLED پردې د تارونو لپاره، د بریښنا په وصلولو سره پیل وکړئ. د ACS758 د VCC پن ستاسو په Arduino باندې د 5V آوټ پوټ سره وصل کړئ، او د GND پن د Arduino په ځمکه (GND) سره وصل کړئ. د ACS758 څخه د سیګنال آوټ پوټ پن (Vout) باید د Arduino په انلاګ داخل پن A0 سره وصل شي.

بیا، د SSD1306 OLED پردې لپاره، د VCC پن د Arduino د 5V آوټ پوټ سره او د GND پن ځمکې سره وصل کړئ. د OLED د SDA پن د Arduino د SDA پن (په ډیرو Arduino بورډونو کې A4) سره او د OLED د SCL پن د SCL پن (په ډیرو Arduino بورډونو کې A5) سره وصل کړئ. ډاډ ترلاسه کړئ چې ټولې اړیکې د باوري عملیاتو لپاره خوندي دي.

د کوډ مثالونه او تفصیل

#define VIN A0 // د Arduino پن A0 د ولتاژ داخل (V in) په توګه تعریف کړئ
const float VCC = 5.0; // د بریښنا رسولو ولتاژ 5V یا 3.3V
const int model = 2; // ماډل دننه کړئ (لاندې وګورئ)

په کوډ کې، متغیر VIN انلاګ پن A0 ته ټاکل شوی، کوم چې به د ACS758 سینسر څخه ولتاژ ولولي. د VCC متغیر د بریښنا رسولو ولتاژ ټاکي، او د model متغیر تعریف کوي چې کوم ACS758 ماډل کارول کیږي، کوم چې په حساسیت او د تولید ولتاژ محاسبو اغیزه کوي.

void loop() {
  float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // د سینسر څخه ولتاژ ولولئ
  float current = voltage / FACTOR; // د ولتاژ پر بنسټ جریان محاسبه کړئ
}

د loop() فنکشن دننه، کوډ د analogRead(VIN) په کارولو سره د سینسر څخه خام ولتاژ لولي او د تعریف شوي حساسیت پر بنسټ یې د جریان ارزښت ته بدلوي. دا د سرکټ څخه د تېرېدونکي جریان ریښتیني وخت څارنه ممکنه کوي.

if(abs(voltage) > cutOff) {
    display.clearDisplay();
    robojaxText("Current:", 0, 22, 2, false);
}

دا شرطي جمله ګوري چې ایا د ولتاژ مطلق ارزښت د cutOff حد څخه لوی دی. که ریښتیا وي، دا پرده پاکوي او OLED د جریان لوستلو سره تازه کوي. دا ډاډ ورکوي چې یوازې د پام وړ جریان ارزښتونه ښودل کیږي، چې په پردې باندې د ګډوډۍ مخه نیسي.

ښودنه / څه تمه وکړئ

کله چې تاسو پروګرام پرمخ وړئ، د OLED پرده به په ریښتیني وخت کې اندازه شوی جریان وښیې. که چیرې هیڅ جریان نه وي، پرده به "No Current" وښیې. ډاډ ترلاسه کړئ چې اړیکې سمې دي ترڅو د داسې ستونزو مخه ونیسئ لکه برعکس قطبي، کوم چې کیدای شي غلط لوستل رامینځته کړي (په ویډیو کې په 05:30 کې).

انځورونه

SSD1306 OLED displaying text
SSD1306 OLED displaying text
SSD1306 OLED display
SSD1306 OLED display
ACS758-sensor-6-pins
ACS758-sensor-6-pins
ACS758-sensor-0
ACS758-sensor-0
ACS758-sensor-1
ACS758-sensor-1
ACS758-sensor-4
ACS758-sensor-4
Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64
Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64
110-Allegro ACS758 current sensor with SSD1306 OLED display for Arduino
ژبه: C++
/*
 * Arduino Sketch for Allegro ACS758 Current Sensor with SSD1306 OLED Display 
 * can be used with 128x64 or 128x32 OLED displays with SSD1306 chip
 * this sensor can measure current at a range of up to 200A
 * It operates with 3.3V or 5V
 * This video requires you to watch the following 2 videos before using this code:
 * 1- ACS758 Sensor https://www.youtube.com/watch?v=SiHfjzcqnU4
 * 2- SSD1306 OLED Display https://www.youtube.com/watch?v=UmYiHTOz-5k
 * 
 * View the video instructions for this code at https://youtu.be/aHg9UrK9s9c
 
 * Written by Ahmad Shamshiri for Robojax Video channel www.Robojax.com
 * Date: June 24, 2018, at 21:44 in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * This code has been downloaded from https://robojax.com
 * 
 */



#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 64 
#define LOGO16_GLCD_WIDTH  128 
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif


///*** ACS758 settings starts
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC   = 5.0;// supply voltage 5V or 3.3V. If using PCB, set to 5V only.
const int model = 2;   // enter the model (see below)

float cutOffLimit = 1.00;// reading cutt off current. 1.00 is 1 Amper

/*
          "ACS758LCB-050B",// for model use 0
          "ACS758LCB-050U",// for model use 1
          "ACS758LCB-100B",// for model use 2
          "ACS758LCB-100U",// for model use 3
          "ACS758KCB-150B",// for model use 4
          "ACS758KCB-150U",// for model use 5
          "ACS758ECB-200B",// for model use 6
          "ACS758ECB-200U"// for model use  7   
sensitivity array is holding the sensitivity of the ACS758
current sensors. Do not change.          
*/
float sensitivity[] ={
          40.0,// for ACS758LCB-050B
          60.0,// for ACS758LCB-050U
          20.0,// for ACS758LCB-100B
          40.0,// for ACS758LCB-100U
          13.3,// for ACS758KCB-150B
          16.7,// for ACS758KCB-150U
          10.0,// for ACS758ECB-200B
          20.0,// for ACS758ECB-200U     
         }; 

/*         
 *   Quiescent output voltage is a factor of VCC that appears at the output       
 *   when the current is zero. 
 *   For bidirectional sensors it is 0.5 x VCC
 *   For unidirectional sensors it is 0.12 x VCC
 *   For model ACS758LCB-050B, the B at the end represents Bidirectional (polarity doesn't matter)
 *   For model ACS758LCB-100U, the U at the end represents Unidirectional (polarity must match)
 *    Do not change.
 */
float quiescent_Output_voltage [] ={
          0.5,// for ACS758LCB-050B
          0.12,// for ACS758LCB-050U
          0.5,// for ACS758LCB-100B
          0.12,// for ACS758LCB-100U
          0.5,// for ACS758KCB-150B
          0.12,// for ACS758KCB-150U
          0.5,// for ACS758ECB-200B
          0.12,// for ACS758ECB-200U            
          };
const float FACTOR = sensitivity[model]/1000;// set sensitivity for selected model
const float QOV =   quiescent_Output_voltage [model] * VCC;// set quiescent Output voltage for selected model
float voltage;// internal variable for voltage
float cutOff = FACTOR/cutOffLimit;// convert current cut off to mV


//**** ACS758 settings ends
void setup()   {                
  Serial.begin(9600);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done

}


void loop() {
   //Robojax.com ACS758 Current Sensor values start
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage_raw - QOV + 0.003 ;// 0.007 is a value to make voltage zero when there is no current
  float current = voltage / FACTOR;
if(abs(voltage) > cutOff ){
    Serial.print("V: ");
    Serial.print(voltage,3);// print voltage with 3 decimal places
    Serial.print("V, I: ");
    Serial.print(current,2); // print the current with 2 decimal places
    Serial.println("A");
 display.clearDisplay();
  robojaxText("V:", 0, 0, 2, false);
  String voltageS  = String(voltage);// get voltage and convert it to string for display
  robojaxText(voltageS +"V", 20, 0, 2, false);  
  robojaxText("Current:", 0, 22, 2, false);
  String currentS  = String(current);// get current and convert it to string for display
  robojaxText(currentS +"A", 0, 40, 3, false);  
  display.display();    
  }else{
    Serial.println("No Current");
   display.clearDisplay();
  robojaxText("No Current", 0, 0, 2, false); 
    display.display();    
  }  
 
   //Robojax.com ACS758 Current Sensor values end
  
    

   delay(500);
}

/*
 * robojaxText(String text, int x, int y,int size, boolean d)
 * text is the text string to be printed
 * x is the integer x position of the text
 * y is the integer y position of the text
 * size is the text size, 1, 2, 3 etc
 * d is either true or false.  Use true to display immediately.
 */
void robojaxText(String text, int x, int y,int size, boolean d) {

  display.setTextSize(size);
  display.setTextColor(WHITE);
  display.setCursor(x,y);
  display.println(text);
  if(d){
    display.display();
  }
  
  delay(100);
}

هغه شیان چې تاسو ورته اړتیا لرئ

سرچینې او حوالې

تر اوسه هیڅ سرچینې نشته.

فایلونه📁

Arduino کتابتونونه (zip)

ډیټاشیټ (pdf)

  • SSD1306 display datasheet
    SSD1306 is a single-chip CMOS OLED/PLED driver with controller for organic / polymer light emitting diode dot-matrix graphic display system. It consists of 128 segments and 64commons. This IC is designed for Common Cathode type OLED panel. The SSD1306 embeds with contrast control, display RAM and oscillator, which reduces the number of external components and power consumption. It has 256-step brightness control. Data/Commands are sent from general MCU through the hardware selectable 6800/8000 series compatible Parallel Interface, I2C interface or Serial Peripheral Interface. It is suitable for many compact portable applications, such as mobile phone sub-display, MP3 player and calculator, etc.
    SSD1306_display_datasheet.pdf 1.79 MB

Fritzing فایل

د کارونکي لارښود

نور فایلونه

  • Alegro ACS Current Library
    Arduino library for Allegro ACS current sensor modules. Provides functions to read current measurements from ACS712 and similar sensors.
    robojax_Alegro_ACS_Current_library.zip 0.02 MB