Luxmètre du joueur chinois

J'aime la culture des plantes et je voulais connaître le niveau d'éclairage, car il existe des niveaux d'éclairage recommandés pour les plantes. Sur aliexpress, un capteur BH1750 calibré a été acheté. Il existe également sur Internet des informations sur le lecteur chinois, qui vous permettent d'en collecter quelque chose, car il existe déjà une bibliothèque pour l'affichage. Et je voulais les croiser: l'écran, l'arduino, le capteur, et bien sûr tout était alimenté par la batterie intégrée au lecteur.

En fait, c'est ce qui s'est passé:



un posemètre compact dans le boîtier du lecteur.

Les caractéristiques du posemètre sont déterminées par le capteur et il peut mesurer l'éclairage de 1 à 65535 lux.

Comme vous pouvez le voir sur la photo à l'écran, il n'y a que des chiffres, pas même des unités de mesure. Je ne l'ai pas fait car je n'en vois pas la nécessité, et l'écran est petit. Il n'y a pas de contrôle de batterie.

J'ai acheté un joueur ici . Je donne le lien car dans ce cas il y a au moins 2 options pour la carte, et j'apporte les contacts pour la mienne.

Il y a un commentaire sur le lecteur: depuis que j'ai quitté mon circuit de charge natif, j'ai dû faire attention: il recharge facilement la batterie et il gonfle. Il vaut mieux ne pas l'utiliser du tout, dans le cas idéal, faire de votre carte un contrôleur de charge, un microcontrôleur, etc.

Assemblage:

1. Démontez soigneusement le lecteur, enregistrez tous les détails! Ils seront toujours utiles.
2. La batterie est temporairement non soudée. Souder le contrôleur natif, prise 3,5 mm (pour casque), fente pour carte mémoire, lampe de poche LED.
3. J'ai besoin d'un Arduino Pro Mini, je n'avais que 5V 16MHz, mais cela fonctionne aussi avec succès à partir de 3,3V. Et bien sûr, vous avez besoin d'un adaptateur USB-UART vers 3,3 V.
4. Besoin d'un fil fin. J'ai du MGTF, je ne me souviens pas du diamètre, mais celui épais pour cette tâche, je le mets à peine dedans, prends immédiatement le plus fin.

Je n'ai pas fait le schéma, les contacts nécessaires sont indiqués sur les photos:






Puisqu'aucune bibliothèque existante pour l'affichage ne me convenait, j'ai écrit mon propre code, y compris le contrôle de l'affichage basé sur l'un d'eux. Le code est divisé en fichiers, compilés dans Arduino IDE 1.6.12.

Luxmeter_mod2.ino
#include <avr/pgmspace.h>
#define pgm     pgm_read_byte
#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;
unsigned int lux;

#define CS      10
#define Data    11
#define Clock   13
#define DC      A0

#define LCD_X        128
#define LCD_Y        64
#define LCD_String    8
#define swap(a, b) { int t = a; a = b; b = t; }

#define LCD_D         1
#define LCD_C         0

byte LCD_RAM[LCD_X*LCD_String];

#define BLACK 1
#define WHITE 0

#define LCDWIDTH 128
#define LCDHEIGHT 64

#define CMD_DISPLAY_OFF   0xAE
#define CMD_DISPLAY_ON    0xAF

#define CMD_SET_DISP_START_LINE  0x40
#define CMD_SET_PAGE  0xB0

#define CMD_SET_COLUMN_UPPER  0x10
#define CMD_SET_COLUMN_LOWER  0x00

#define CMD_SET_ADC_NORMAL  0xA0
#define CMD_SET_ADC_REVERSE 0xA1

#define CMD_SET_DISP_NORMAL 0xA6
#define CMD_SET_DISP_REVERSE 0xA7

#define CMD_SET_ALLPTS_NORMAL 0xA4
#define CMD_SET_ALLPTS_ON  0xA5
#define CMD_SET_BIAS_9 0xA2 
#define CMD_SET_BIAS_7 0xA3

#define CMD_RMW  0xE0
#define CMD_RMW_CLEAR 0xEE
#define CMD_INTERNAL_RESET  0xE2
#define CMD_SET_COM_NORMAL  0xC0
#define CMD_SET_COM_REVERSE  0xC8
#define CMD_SET_POWER_CONTROL  0x28
#define CMD_SET_RESISTOR_RATIO  0x20
#define CMD_SET_VOLUME_FIRST  0x81
#define  CMD_SET_VOLUME_SECOND  0
#define CMD_SET_STATIC_OFF  0xAC
#define  CMD_SET_STATIC_ON  0xAD
#define CMD_SET_STATIC_REG  0x0
#define CMD_SET_BOOSTER_FIRST  0xF8
#define CMD_SET_BOOSTER_234  0
#define  CMD_SET_BOOSTER_5  1
#define  CMD_SET_BOOSTER_6  3
#define CMD_NOP  0xE3
#define CMD_TEST  



Font.ino
#include <avr/pgmspace.h>
//  1632 
static const char mass16x32 [10][64] PROGMEM ={
{   0xF8, 0xFC, 0xFA, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFA, 0xFC, 0xF8, //0
    0x3F, 0x7F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x3F,
    0xFE, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFE,
    0x1F, 0x3F, 0x5F, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x5F, 0x3F, 0x1F},

{   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFC, 0xF8, //1
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x3F,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFE,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x1F},

    {0x00, 0x00, 0x02, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFA, 0xFC, 0xF8, //2
    0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xBF, 0x7F, 0x3F,
    0xFE, 0xFF, 0xFE, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
    0x1F, 0x3F, 0x5F, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x40, 0x00, 0x00},

    {0x00, 0x00, 0x02, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFA, 0xFC, 0xF8, //3
    0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xBF, 0x7F, 0x3F,
    0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0xFF, 0xFE,
    0x00, 0x00, 0x40, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x5F, 0x3F, 0x1F},

    {0xF8, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFC, 0xF8, //4
    0x3F, 0x7F, 0xBF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xBF, 0x7F, 0x3F,
    0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0xFF, 0xFE,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x1F},

    {0xF8, 0xFC, 0xFA, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x02, 0x00, 0x00, //5
    0x3F, 0x7F, 0xBF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0xFF, 0xFE,
    0x00, 0x00, 0x40, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x5F, 0x3F, 0x1F},

    {0xF8, 0xFC, 0xFA, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x02, 0x00, 0x00, //6
    0x3F, 0x7F, 0xBF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x00, 0x00,
    0xFE, 0xFF, 0xFE, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0xFF, 0xFE,
    0x1F, 0x3F, 0x5F, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x5F, 0x3F, 0x1F},

    {0x00, 0x00, 0x02, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFA, 0xFC, 0xF8, //7
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x3F,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFE,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x1F},

    {0xF8, 0xFC, 0xFA, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFA, 0xFC, 0xF8, //8
    0x3F, 0x7F, 0xBF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xBF, 0x7F, 0x3F,
    0xFE, 0xFF, 0xFE, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0xFF, 0xFE,
    0x1F, 0x3F, 0x5F, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x5F, 0x3F, 0x1F},

    {0xF8, 0xFC, 0xFA, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFA, 0xFC, 0xF8, //9
    0x3F, 0x7F, 0xBF, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xBF, 0x7F, 0x3F,
    0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0xFF, 0xFE,
    0x00, 0x00, 0x40, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x5F, 0x3F, 0x1F}};

<source lang="arduino">


LCD.ino
#include <avr/pgmspace.h>
//====================================================== 
void Clear_LCD() {
  for (int index = 0; index < 864 ; index++) {
    LCD_RAM[index] = (0x00);
  }
}

//======================================================= 
void dWrite(byte pin, byte val) {
  byte bit = digitalPinToBitMask(pin);
  volatile byte *out;
  out = portOutputRegister(digitalPinToPort(pin));
  (val) ? *out |= bit : *out &= ~bit;
}

#define _BV(bit) (1<<(bit))
//========================================================= 8 
void SendByte(byte mode, byte c) {
  dWrite(CS, 0);
  (mode) ? dWrite(DC, 1) : dWrite(DC, 0);
  for (byte i = 0; i <8; i++) {
    dWrite(Clock, 0);
    (c & 0x80) ? dWrite(Data, 1) : dWrite(Data, 0);
    dWrite(Clock, 1);
    c <<= 1;
  }
}

//===================================================== 
void Update() {
  for (byte p = 0; p < 8; p++) {
    //SendByte(LCD_C, CMD_SET_PAGE | pagemap[p]);
    SendByte(LCD_C, CMD_SET_PAGE | p);

    byte col = 0;

    SendByte(LCD_C, CMD_SET_COLUMN_LOWER | (1 & 0xf));
    SendByte(LCD_C, CMD_SET_COLUMN_UPPER | ((1 >> 4) & 0x0F));
    SendByte(LCD_C, CMD_RMW);

    for (byte col = 0; col < LCD_X; col++) {
      SendByte(LCD_D, LCD_RAM[(LCD_X * p) + col]);
    }
  }
}


//=================================================== 
void drawPixel (byte x, byte y, boolean color) {
  if ((x < 0) || (x >= LCD_X) || (y < 0) || (y >= LCD_Y)) return;

  if (color) LCD_RAM[x + (y / 8)*LCD_X] |= _BV(y % 8);
  else       LCD_RAM[x + (y / 8)*LCD_X] &= ~_BV(y % 8);
}

//====================================================== 
void drawBitmap(byte x, byte y, const char *bitmap, byte w, byte h, boolean color) {
  for (int16_t j = 0; j < h; j++) {
    for (int16_t i = 0; i < w; i++ ) {
      if (pgm(bitmap + i + (j / 8)*w) & _BV(j % 8)) {
        drawPixel(x + i, y + j, color);
      }
    }
  }
}

//========================================================================
//                         
//========================================================================




//=================================================== 
void Inicialize() {
  pinMode(CS,    OUTPUT);
  pinMode(Data,  OUTPUT);
  pinMode(Clock, OUTPUT);
  pinMode(DC, OUTPUT);

  //  
  dWrite(CS, 0);
  delay(500);

  SendByte(LCD_C, CMD_SET_BIAS_7);              // LCD bias select
  SendByte(LCD_C, CMD_SET_ADC_NORMAL);          // ADC select
  SendByte(LCD_C, CMD_SET_COM_REVERSE);          // SHL select
  SendByte(LCD_C, CMD_SET_DISP_START_LINE);     // Initial display line
  SendByte(LCD_C, CMD_SET_POWER_CONTROL | 0x4); // turn on voltage converter (VC=1, VR=0, VF=0)
  delay(50);
  SendByte(LCD_C, CMD_SET_POWER_CONTROL | 0x6); // turn on voltage regulator (VC=1, VR=1, VF=0)
  delay(50);
  SendByte(LCD_C, CMD_SET_POWER_CONTROL | 0x7); // turn on voltage follower (VC=1, VR=1, VF=1)
  delay(10);
  SendByte(LCD_C, CMD_SET_RESISTOR_RATIO | 0x6); // set lcd operating voltage (regulator resistor, ref voltage resistor)

  SendByte(LCD_C, CMD_DISPLAY_ON);
  SendByte(LCD_C, CMD_SET_ALLPTS_NORMAL);

  SendByte(LCD_C, CMD_SET_DISP_REVERSE);

  SendByte(LCD_C, CMD_SET_VOLUME_FIRST);
  SendByte(LCD_C, CMD_SET_VOLUME_SECOND | (0 & 0x3f));

  Clear_LCD();
  Update();
}

//=========================  1632    XY
void simb16x32(byte x, byte y, boolean color, byte c) {
  for (byte k = 0; k < 4; k++) {
    for (byte i = 0; i < 16; i++) {
      byte line = pgm(&(mass16x32[c][i + k * 16]));
      for (byte j = 0; j < 8; j++) {
        (line & 0x01) ? drawPixel(x + i, y + j + k * 8, color) : drawPixel(x + i, y + j + k * 8, !color);
        line >>= 1;
      }
    }
  }
}
<source lang="arduino">


Main.ino
#include <avr/pgmspace.h>
void setup(){
  Inicialize();
  lightMeter.begin();
}
+
void loop(){
  lux = lightMeter.readLightLevel();
  simb16x32(95,  17, 1, lux%10);
  lux/=10;
  simb16x32(75,  17, 1, lux%10);
  lux/=10;
  simb16x32(55,  17, 1, lux%10);
  lux/=10;
  simb16x32(35,  17, 1, lux%10);
  lux/=10;
  simb16x32(15,  17, 1, lux%10);

  Update();
  delay(300);
}
<source lang="arduino">


Je veux dire tout de suite qu'il s'agit plus d'un indicateur que d'un appareil de mesure, mais il peut être utile d'avoir un tel indicateur, de plus, il faudra un soir à assembler s'il y a une certaine expérience.

Il y a aussi de la vidéo, mais pas de son. Je voulais l'enregistrer séparément, mais il s'est avéré qu'aucun de mes microphones ne peut le faire normalement.

Source: https://habr.com/ru/post/fr400989/


All Articles