Skip to content

Lpcxpresso4337 Om13070 Pin Assignments

=============================================================================================

ARQUIVO MAIN

#include “ST7567.h”
#include “BMP180.h”
#include “DHT.h”
#define BMP180_ADDRESS 0x77<<1
DigitalOut myled(LED1);

Serial pc(USBTX, USBRX);
uint32_t delt_t, count, tempcount;
float temperature, pressure, pressure_mb, temppress, altitude;
BMP180 bmp180; // Inicializa o sensor BMP-180
DHT sensor(P2_6, DHT11); // Inicializa o sensor DHT22
Timer t;
ST7567 lcd(D11, D13, D12, D9, D10); // mosi, sclk, reset, A0, nCS
AnalogIn pot_A3(A3); // configura entrada analogica A3 para sensor de direção do vento
AnalogIn pot_A4(A4); // configura entrada analogica A4 para sensor umidade do solo

//———————————————
// INTERRUPCAO PARA LEITURA DA VELOCIDADE DO VENTO
InterruptIn _intVelocidadeVento(P6_5);

int pulsosVelocidadeVento = 0;
void contadorVelocidadeVento()
{
_intVelocidadeVento.disable_irq();
wait(0.1); // delay para evitar ruidos

pulsosVelocidadeVento++;
_intVelocidadeVento.enable_irq();
}
//———————————————
//———————————————
// INTERRUPCAO PARA CONTAGEM DO PLUVIOMETRO

InterruptIn _intPluviometro(P2_13);

int pulsosPluviometro = 0;
void contadorPluviometro()
{
_intPluviometro.disable_irq();
wait(0.1);
pulsosPluviometro++;
_intPluviometro.enable_irq();
}
//———————————————
int main()
{

_intVelocidadeVento.rise(&contadorVelocidadeVento);

_intPluviometro.rise(&contadorPluviometro);

float sensorVelocidadeVento = 0;
float sensorDirecaoVento = 0;
float sensorTemperatura = 0;
float sensorUmidade = 0;
float sensorPressao = 0;
float sensorPluviometro = 0;
float sensorUmidadeSolo = 0;

int err;

int tempo = 0;
int tempo_1s = 0;
int tempo_2s = 0;
int tempo_5s = 0;

int tempo_1s_vel_vento = 0;

t.start();

// Read the WHO_AM_I register of the BMP-180, this is a good test of communication
uint8_t c = bmp180.readByte(BMP180_ADDRESS, BMP180_WHO_AM_I);
if(c == 0x55)
{
wait(1);
bmp180.BMP180Calibration();
}
lcd.set_contrast(0x35); //configura contraste do Display
lcd.cls(); //Limpa Display

wait(1); //espera 1segundo

while(true) { // loop principal

//************************************************************************
// LEITURA DO SENSOR DE PRESSAO E TEMPERATURA

if(tempo_1s==1)
{
tempo_1s = 0;
sensorTemperatura = (float)bmp180.BMP180GetTemperature()/10.0f; // Recebe o valor da temperatura em graus Celcius
temppress += (float)bmp180.BMP180GetPressure(); // Recebe o valor da pressão em Pa
tempcount++;

wait_ms(100); // Delay para fazer a conversão dos valores
pressure = temppress/tempcount; // use average pressure for reading to get ultra-high resolution
pressure_mb = pressure/100; // Conversão do valor da pressão de “Pascal” para “milibar”
//pressure_mb = pressure/100000; // Conversão do valor da pressão de “Pascal” para “milibar”
sensorPressao = pressure_mb;

count = t.read_ms();
temppress = 0;
tempcount = 0;
}
//************************************************************************
//************************************************************************
// lEITURA DA PRESSÃO – SENSOR DHT22

if(tempo_5s==5)
{
tempo_5s = 0;
err = sensor.readData();
if(err==0) sensorUmidade = sensor.ReadHumidity();

}
//************************************************************************
//************************************************************************
// LEITURA DO SENSOR DE UMIDADE DO SOLO

sensorUmidadeSolo = pot_A4*100;
//************************************************************************

//************************************************************************
// LEITURA DO SENSOR DE DIREÇÃO DO VENTO

sensorDirecaoVento = pot_A3*360;
//************************************************************************
//************************************************************************
// LEITURA DO PLUVIOMETRO
// 0,25mm por pulso

sensorPluviometro = 0.25*pulsosPluviometro;
//************************************************************************
//************************************************************************
// LEITURA DO SENSOR DE VELOCIDADE DO VENTO
// V = R*W => 3 pulsos por volta => pulsos*3*R*W
// W = 1 volta = 2*pi rad/s
// R = 0,07
// V = pulsos*3*0.07*6.28 => 1,32*pulsos m/s
// V = R*W => 1 pulsos por volta => pulsos*1*R*W
// V = pulsos*1*0.07*6.28 => 0,44*pulsos m/s

if(tempo_1s_vel_vento==1)
{
sensorVelocidadeVento = (tempo_1s_vel_vento*132)/100;
tempo_1s_vel_vento = 0;
pulsosVelocidadeVento = 0;
}
//************************************************************************
//************************************************************************
// ENVIO DOS DADOS E IMPRESSAO DOS MESMOS NO DISPLAY

if(tempo_2s==2)
{
tempo_2s = 0;

lcd.locate(0, 1);
lcd.printf(“Velocidade = %4.2f m/s rn”,sensorVelocidadeVento);
pc.printf(“{S00:%4.2f} rn”,sensorVelocidadeVento);
lcd.locate(0, 1 + 8);
lcd.printf(“Direcao = %4.2f graus rn”,sensorDirecaoVento);
pc.printf(“{S01:%4.2f} rn”,sensorDirecaoVento);
lcd.locate(0, 1 + 16);
lcd.printf(“Temperatura = %4.2f C rn”,sensorTemperatura);
pc.printf(“{S02:%4.2f} rn”,sensorTemperatura);
lcd.locate(0, 1 + 24);
lcd.printf(“Umidade = %4.2f % rn”,sensorUmidade);
pc.printf(“{S03:%4.2f} rn”,sensorUmidade);
lcd.locate(0, 1 + 32);
lcd.printf(“Pressao = %4.2f mbar rn”,sensorPressao);
pc.printf(“{S04:%4.2f} rn”,sensorPressao);
lcd.locate(0, 1 + 40);
lcd.printf(“Pluviometro = %4.2f mm rn”,sensorPluviometro);
pc.printf(“{S05:%4.2f} rn”,sensorPluviometro);
lcd.locate(0, 1 + 48);
lcd.printf(“Umidade do solo = %4.2f rn”,sensorUmidadeSolo);
pc.printf(“{S06:%4.2f} rn”,sensorUmidadeSolo);
}
//************************************************************************
//************************************************************************
// FUNCAO DOS FLAGS DOS TIMERS

tempo = t.read_ms();
if(tempo>=1000)
{
//pc.printf(“%4.2f rn”,sensorPluviometro);
//pc.printf(“%d rn”,pulsosPluviometro);
//pc.printf(“%d rn”,pulsosVelocidadeVento);

tempo = 0;
t.reset();
myled = !myled; // Inverte o estado do led

tempo_1s++;
tempo_2s++;
tempo_5s++;
tempo_1s_vel_vento++;

//myled = !myled;
//wait(2); // Espera 2 segundos
}
//************************************************************************

}
}

==========================================================================================

ARQUIVO DTH.h

#ifndef MBED_DHT_H
#define MBED_DHT_H

#include “mbed.h”

enum eType{
DHT11 = 11,
SEN11301P = 11,
RHT01 = 11,
DHT22 = 22,
AM2302 = 22,
SEN51035P = 22,
RHT02 = 22,
RHT03 = 22
} ;

enum eError {
ERROR_NONE = 0,
BUS_BUSY =1,
ERROR_NOT_PRESENT =2 ,
ERROR_ACK_TOO_LONG =3 ,
ERROR_SYNC_TIMEOUT = 4,
ERROR_DATA_TIMEOUT =5 ,
ERROR_CHECKSUM = 6,
ERROR_NO_PATIENCE =7
} ;

typedef enum {
CELCIUS =0 ,
FARENHEIT =1,
KELVIN=2
} eScale;
class DHT {

public:

DHT(PinName pin,int DHTtype);
~DHT();
int readData(void);
float ReadHumidity(void);
float ReadTemperature(eScale Scale);
float CalcdewPoint(float celsius, float humidity);
float CalcdewPointFast(float celsius, float humidity);

private:
time_t _lastReadTime;
float _lastTemperature;
float _lastHumidity;
PinName _pin;
bool _firsttime;
int _DHTtype;
int DHT_data[6];
float CalcTemperature();
float CalcHumidity();
float ConvertCelciustoFarenheit(float);
float ConvertCelciustoKelvin(float);

};

#endif

=================================================================================

ARQUIVO BPM180.h

#ifndef BMP180_H
#define BMP180_H

#include “mbed.h”

#define BMP180_ADDRESS 0x77<<1 // I2C address of BMP180, eight bit address on mbed
#define BMP180_WHO_AM_I 0xD0 // WHO_AM_I id of BMP180, should return 0x55
#define BMP180_RESET 0xE0
#define BMP180_CONTROL 0xF4
#define BMP180_OUT_MSB 0xF6
#define BMP180_OUT_LSB 0xF7
#define BMP180_OUT_XLSB 0xF8

// Set initial input parameters

enum OSS { // BMP-085 sampling rate
OSS_0 = 0, // 4.5 ms conversion time
OSS_1, // 7.5
OSS_2, // 13.5
OSS_3 // 25.5
};

uint8_t OSS = OSS_3; // maximum pressure resolution

//Set up I2C, (SDA,SCL)
//I2C i2c(I2C_SDA, I2C_SCL);
I2C i2c(P2_3, P2_4);

// These are constants used to calculate the temperature and pressure from the BMP-180 sensor
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md, b5;
uint16_t ac4, ac5, ac6;

class BMP180 {

protected:

public:
//===================================================================================================================
//====== Set of useful function to access pressure and temperature data
//===================================================================================================================

void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
char data_write[2];
data_write[0] = subAddress;
data_write[1] = data;
i2c.write(address, data_write, 2, 0);
}

char readByte(uint8_t address, uint8_t subAddress)
{
char data[1]; // will store the register data
char data_write[1];
data_write[0] = subAddress;
i2c.write(address, data_write, 1, 1); // no stop
i2c.read(address, data, 1, 0);
return data[0];
}

void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
{
char data[14];
char data_write[1];
data_write[0] = subAddress;
i2c.write(address, data_write, 1, 1); // no stop
i2c.read(address, data, count, 0);
for(int ii = 0; ii < count; ii++) {
dest[ii] = data[ii];
}
}

// Stores all of the BMP180’s calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
// These BMP-180 functions were adapted from Jim Lindblom of SparkFun Electronics
void BMP180Calibration()
{
ac1 = readByte(BMP180_ADDRESS, 0xAA) << 8 | readByte(BMP180_ADDRESS, 0xAB);
ac2 = readByte(BMP180_ADDRESS, 0xAC) << 8 | readByte(BMP180_ADDRESS, 0xAD);
ac3 = readByte(BMP180_ADDRESS, 0xAE) << 8 | readByte(BMP180_ADDRESS, 0xAF);
ac4 = readByte(BMP180_ADDRESS, 0xB0) << 8 | readByte(BMP180_ADDRESS, 0xB1);
ac5 = readByte(BMP180_ADDRESS, 0xB2) << 8 | readByte(BMP180_ADDRESS, 0xB3);
ac6 = readByte(BMP180_ADDRESS, 0xB4) << 8 | readByte(BMP180_ADDRESS, 0xB5);
b1 = readByte(BMP180_ADDRESS, 0xB6) << 8 | readByte(BMP180_ADDRESS, 0xB7);
b2 = readByte(BMP180_ADDRESS, 0xB8) << 8 | readByte(BMP180_ADDRESS, 0xB9);
mb = readByte(BMP180_ADDRESS, 0xBA) << 8 | readByte(BMP180_ADDRESS, 0xBB);
mc = readByte(BMP180_ADDRESS, 0xBC) << 8 | readByte(BMP180_ADDRESS, 0xBD);
md = readByte(BMP180_ADDRESS, 0xBE) << 8 | readByte(BMP180_ADDRESS, 0xBF);
}

// Temperature returned will be in units of 0.1 deg C
int16_t BMP180GetTemperature()
{
int16_t ut = 0;
writeByte(BMP180_ADDRESS, 0xF4, 0x2E); // start temperature measurement
wait(0.005);
uint8_t rawData[2] = {0, 0};
readBytes(BMP180_ADDRESS, 0xF6, 2, &rawData[0]); // read raw temperature measurement
ut = (((int16_t) rawData[0] << 8) | rawData[1]);

long x1, x2;

x1 = (((long)ut – (long)ac6)*(long)ac5) >> 15;
x2 = ((long)mc << 11)/(x1 + md);
b5 = x1 + x2;

return ((b5 + 8)>>4);
}

// Calculate pressure read calibration values
// b5 is also required so BMP180GetTemperature() must be called first.
// Value returned will be pressure in units of Pa.
long BMP180GetPressure()
{
long up = 0;
writeByte(BMP180_ADDRESS, 0xF4, 0x34 | OSS << 6); // Configure pressure measurement for highest resolution
wait((5.0f + 8.0f*3.0f)/1000.0f); // delay 5 ms at lowest resolution, 29 ms at highest
uint8_t rawData[3] = {0, 0, 0};
readBytes(BMP180_ADDRESS, 0xF6, 3, &rawData[0]); // read raw pressure measurement of 19 bits
up = (((long) rawData[0] << 16) | ((long)rawData[1] << 8) | rawData[2]) >> (8 – OSS);

long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;

b6 = b5 – 4000;
// Calculate B3
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;

// Calculate B4
x1 = (ac3 * b6)>>13;
x2 = (b1 * ((b6 * b6)>>12))>>16;
x3 = ((x1 + x2) + 2)>>2;
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;

b7 = ((unsigned long)(up – b3) * (50000>>OSS));
if (b7 < 0x80000000)
p = (b7<<1)/b4;
else
p = (b7/b4)<<1;

x1 = (p>>8) * (p>>8);
x1 = (x1 * 3038)>>16;
x2 = (-7357 * p)>>16;
p += (x1 + x2 + 3791)>>4;

return p;
}

};
#endif

==========================================================================================

ARQUIVO DTH.ccp

#include “DHT.h”

#define DHT_DATA_BIT_COUNT 41

DHT::DHT(PinName pin,int DHTtype) {
_pin = pin;
_DHTtype = DHTtype;
_firsttime=true;
}

DHT::~DHT() {
}

int DHT::readData() {
int i, j, retryCount,b;
unsigned int bitTimes[DHT_DATA_BIT_COUNT];

eError err = ERROR_NONE;
time_t currentTime = time(NULL);

DigitalInOut DHT_io(_pin);

for (i = 0; i < DHT_DATA_BIT_COUNT; i++) {
bitTimes[i] = 0;
}

if (!_firsttime) {
if (int(currentTime – _lastReadTime) < 2) {
err = ERROR_NO_PATIENCE;
return err;
}
} else {
_firsttime=false;
_lastReadTime=currentTime;
}
retryCount = 0;

do {
if (retryCount > 125) {
err = BUS_BUSY;
return err;

==============================================================================================

ARQUIVO ST7567.h

*/

/* mbed library for the LPC General Purpose Shield 128*64 pixel LCD
* use ST7567 controller
* Copyright (c) 2015 Toyomasa Watarai
*/

#ifndef ST7567_H
#define ST7567_H

#include “mbed.h”
#include “GraphicsDisplay.h”

// some defines for the DMA use
#define DMA_CHANNEL_ENABLE 1
#define DMA_TRANSFER_TYPE_M2P (1UL << 11)
#define DMA_CHANNEL_TCIE (1UL << 31)
#define DMA_CHANNEL_SRC_INC (1UL << 26)
#define DMA_MASK_IE (1UL << 14)
#define DMA_MASK_ITC (1UL << 15)
#define DMA_SSP1_TX (1UL << 2)
#define DMA_SSP0_TX (0)
#define DMA_DEST_SSP1_TX (2UL << 6)
#define DMA_DEST_SSP0_TX (0UL << 6)

#define LCD_FB_SIZE 1024

#define MAX_PIXEL_X 128
#define MAX_PIXEL_Y 64

/** Draw mode
* NORMAl
* XOR set pixel by xor the screen
*/
enum {LCD_NORMAL, LCD_XOR};

/** Bitmap
*/
struct Bitmap{
int xSize;
int ySize;
int Byte_in_Line;
char* data;
};

class ST7567 : public GraphicsDisplay
{
public:
/** Create a ST7567 object connected to SPI1
*
*/

ST7567(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name = “LCD”);
/** Get the width of the screen in pixel
*
* @param
* @returns width of screen in pixel
*
*/
virtual int width();

/** Get the height of the screen in pixel
*
* @returns height of screen in pixel
*
*/
virtual int height();

/** Draw a pixel at x,y black or white
*
* @param x horizontal position
* @param y vertical position
* @param colour ,1 set pixel ,0 erase pixel
*/
virtual void pixel(int x, int y,int colour);

/** draw a circle
*
* @param x0,y0 center
* @param r radius
* @param colour ,1 set pixel ,0 erase pixel
*
*/
void circle(int x, int y, int r, int colour);

/** draw a filled circle
*
* @param x0,y0 center
* @param r radius
* @param color ,1 set pixel ,0 erase pixel
*
* use circle with different radius,
* can miss some pixel
*/
void fillcircle(int x, int y, int r, int colour);

/** draw a 1 pixel line
*
* @param x0,y0 start point
* @param x1,y1 stop point
* @param color ,1 set pixel ,0 erase pixel
*
*/
void line(int x0, int y0, int x1, int y1, int colour);

/** draw a rect
*
* @param x0,y0 top left corner
* @param x1,y1 down right corner
* @param color 1 set pixel ,0 erase pixel
* *
*/
void rect(int x0, int y0, int x1, int y1, int colour);

/** draw a filled rect
*
* @param x0,y0 top left corner
* @param x1,y1 down right corner
* @param color 1 set pixel ,0 erase pixel
*
*/
void fillrect(int x0, int y0, int x1, int y1, int colour);

/** copy display buffer to lcd
*
*/

void copy_to_lcd(void);

/** set the orienation of the screen
*
*/
void set_contrast(unsigned int o);

/** read the contrast level
*
*/
unsigned int get_contrast(void);
/** invert the screen
*
* @param o = 0 normal, 1 invert
*/
void invert(unsigned int o);

/** clear the screen
*
*/
virtual void cls(void);

/** set the drawing mode
*
* @param mode NORMAl or XOR
*/

void setmode(int mode);

virtual int columns(void);

/** calculate the max number of columns
*
* @returns max column
* depends on actual font size
*
*/
virtual int rows(void);

/** put a char on the screen
*
* @param value char to print
* @returns printed char
*
*/
virtual int _putc(int value);

/** draw a character on given position out of the active font to the LCD
*
* @param x x-position of char (top left)
* @param y y-position
* @param c char to print
*
*/
virtual void character(int x, int y, int c);

/** setup cursor position
*
* @param x x-position (top left)
* @param y y-position
*/
virtual void locate(int x, int y);

/** setup auto update of screen
*
* @param up 1 = on , 0 = off
* if switched off the program has to call copy_to_lcd()
* to update screen from framebuffer
*/
void set_auto_up(unsigned int up);

/** get status of the auto update function
*
* @returns if auto update is on
*/
unsigned int get_auto_up(void);

/** Vars */
SPI _spi;
DigitalOut _reset;
DigitalOut _A0;
DigitalOut _CS;
unsigned char* font;
unsigned int draw_mode;
/** select the font to use
*
* @param f pointer to font array
*
* font array can created with GLCD Font Creator from http://www.mikroe.com
* you have to add 4 parameter at the beginning of the font array to use:
* – the number of byte / char
* – the vertial size in pixel
* – the horizontal size in pixel
* – the number of byte per vertical line
* you also have to change the array to char[]
*
*/
void set_font(unsigned char* f);

/** print bitmap to buffer
*
* @param bm Bitmap in flash

The LPC4357/53/37/33 are ARM Cortex-M4 based microcontrollers for embedded applications which include an ARM Cortex-M0 coprocessor, up to 1 MB of flash and 136 kB of on-chip SRAM, 16 kB of EEPROM memory, advanced configurable peripherals such as the State Configurable Timer (SCT) and the Serial General Purpose I/O (SGPIO) interface, two High-speed USB controllers, Ethernet, LCD, an external memory controller, and multiple digital and analog peripherals. The LPC4357/53/37/33 operate at CPU frequencies of up to 204 MHz.

The ARM Cortex-M4 is a next generation 32-bit core that offers system enhancements such as low power consumption, enhanced debug features, and a high level of support block integration. The ARM Cortex-M4 CPU incorporates a 3-stage pipeline, uses a Harvard architecture with separate local instruction and data buses as well as a third bus for peripherals, and includes an internal prefetch unit that supports speculative branching. The ARM Cortex-M4 supports single-cycle digital signal processing and SIMD instructions. A hardware floating-point processor is integrated in the core.

The ARM Cortex-M0 coprocessor is an energy-efficient and easy-to-use 32-bit core which is code- and tool-compatible with the Cortex-M4 core. The Cortex-M0 coprocessor, designed as a replacement for existing 8/16-bit microcontrollers, offers up to 204 MHz performance with a simple instruction set and reduced code size.