ESP32 Welcome screen transition to another screen? - esp32

I'm making a simple car gauge, I want to add a little personal touch nothing special.
Setup: ESP32 and ST7735S with no SD card.
At the beginning I want to add a boot screen ( picture- I use flash memory for this because I have no SD card tftIcons.ino)
After like 5s I want to transition from picture to my gauges ( simple print code for now) But I don't know how to stich these two together to get what I want.
The code for Welcome screen/ Boot is:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include "bitmaps.h"
#include "bitmapsLarge.h"
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 5
#define TFT_RST 4 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.initR(INITR_BLACKTAB);
tft.setRotation(0);
tft.fillScreen(ST7735_BLACK);
//Case 2: Multi Colored Images/Icons
int h = 160,w = 128, row, col, buffidx=0;
for (row=0; row<h; row++) { // For each scanline...
for (col=0; col<w; col++) { // For each pixel...
//To read from Flash Memory, pgm_read_XXX is required.
//Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
tft.drawPixel(col, row, pgm_read_word(evive_in_hand + buffidx));
buffidx++;
} // end pixel
}
}
void loop() {
}
The code for the gauges is:
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#define TFT_CS 5
#define TFT_RST 4 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));
// Use this initializer if using a 1.8" TFT screen:
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // set display orientation
}
void loop() {
tft.fillScreen(ST77XX_BLACK);
print_text(20,5,"1.54",5,ST77XX_GREEN);
print_text(70,50,"BAR",2,ST77XX_GREEN);
print_text(5,90,"Temp motora: 81'C",1,ST77XX_WHITE);
print_text(5,100,"Temp usisa: 30'C",1,ST77XX_BLUE);
print_text(146,116,"AM",1,ST77XX_WHITE);
delay(5000);
}
void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
Can someone tell me how can I make when I power on ESP32 to show Welcome screen/ boot screen for 5s, then automatically transition to Gauges screen ?
EDIT: When I join these two
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include "bitmaps.h"
#include "bitmapsLarge.h"
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 5
#define TFT_RST 4 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.initR(INITR_BLACKTAB);
tft.setRotation(0);
tft.fillScreen(ST7735_BLACK);
//Case 2: Multi Colored Images/Icons
int h = 160,w = 128, row, col, buffidx=0;
for (row=0; row<h; row++) { // For each scanline...
for (col=0; col<w; col++) { // For each pixel...
//To read from Flash Memory, pgm_read_XXX is required.
//Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
tft.drawPixel(col, row, pgm_read_word(evive_in_hand + buffidx));
buffidx++;
} // end pixel
}
delay(5000); // Delay 5s, then run the code down?
}
// Timer
float p = 3.1415926;
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));
// Use this initializer if using a 1.8" TFT screen:
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // set display orientation
void loop() {
tft.fillScreen(ST77XX_BLACK);
print_text(20,5,"1.54",5,ST77XX_GREEN);
print_text(70,50,"BAR",2,ST77XX_GREEN);
print_text(5,90,"Temp motora: 81'C",1,ST77XX_WHITE);
print_text(5,100,"Temp usisa: 30'C",1,ST77XX_BLUE);
print_text(146,116,"AM",1,ST77XX_WHITE);
delay(5000);
}
void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
I get exit status 1
'Serial' does not name a type

#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include "bitmaps.h"
#include "bitmapsLarge.h"
#define TFT_CS 5
#define TFT_RST 4 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));
tft.initR(INITR_BLACKTAB);
tft.setRotation(0);
tft.fillScreen(ST7735_BLACK);
//Case 2: Multi Colored Images/Icons
int h = 160,w = 128, row, col, buffidx=0;
for (row=0; row<h; row++) { // For each scanline...
for (col=0; col<w; col++) { // For each pixel...
//To read from Flash Memory, pgm_read_XXX is required.
//Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
tft.drawPixel(col, row, pgm_read_word(evive_in_hand + buffidx));
buffidx++;
} // end pixel
}
delay(5000);
// Use this initializer if using a 1.8" TFT screen:
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // set display orientation
}
void loop() {
tft.fillScreen(ST77XX_BLACK);
print_text(20,5,"1.54",5,ST77XX_GREEN);
print_text(70,50,"BAR",2,ST77XX_GREEN);
print_text(5,90,"Temp motora: 81'C",1,ST77XX_WHITE);
print_text(5,100,"Temp usisa: 30'C",1,ST77XX_BLUE);
print_text(146,116,"AM",1,ST77XX_WHITE);
delay(5000);
}
void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
I fount out how. You can only have one void setup and void loop. You cant c/p stich two together

Related

Issue with Interfacing atmega328p with Bluetooth

I’m trying to interface atmega328p with Blutooth HC-0.
I was following the example in Atmega328P datasheet in USART section.
The code is simply trying to send a letter 'b' to Bluetooth terminal on mobile phone and receive a letter. If the received letter is 'a', an LED on PORTB0 will turn on, if the letter is 'c', the LED will turn off. But unfortunately nothing is working.
Connection between atmega328P and HC-05 is as follows:
HC-05 -> Atmega328P
RXD -> pin3
TXD -> pin2
GND -> pin8
VCC -> pin7
Bluetooth light is turning on and off, and is connected successfully to mobile phone but no data is received, and when the letters 'a' and 'c' are sent nothing happens with LED connected to PORTB0.
The code is shown here. Thank you for any help!
#define F_CPU 16000000UL // Clock Speed
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
char data;
char data2 = 'b';
void USART_Init(unsigned int ubrr)
{
/* Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)(ubrr);
/* Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}
char USART_Receive(void)
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
return UDR0;
}
void USART_Transmit(char data)
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) );
/* Put data into buffer, sends the data */
UDR0 = data;
}
int main(void)
{
DDRB = 0b00000001;
PORTB = 0b00000000;
USART_Init(MYUBRR);
while (1) {
data = USART_Receive();
USART_Transmit(data2);
if (data == 'a') {
PORTB = 0b00000001;
} else if (data == 'c') {
PORTB = 0b00000000;
}
}
}

AVR Atmega32a USART library isn't working

/*
RC_Car_AVR.c
Created: 4/18/2018 7:55:07 PM
Author :
*/
#define F_CPU 16000000
#define BAUD 9600
#define TUBRR (((F_CPU / 16) / BAUD) - 1)
#include <avr/io.h>
#include <util/delay.h>
char Read;
void USART_Init(void){
UBRRL = TUBRR;
UCSRB = (1<<TXEN)|(1<<RXEN);
UCSRC = (1<<UCSZ1)|(1<<UCSZ0);
}
char USART_Receive(void){
/* Wait for data to be received */
while (!(UCSRA & (1<<RXC)));
/* Get and return received data from buffer */
return UDR;
}
int main(void){
USART_Init();
DDRB |= (1<<0);
PORTB |= (1<<0);
while (1){
Read = USART_Receive();
if(Read == 'F'){
PORTB ^= (1<<0);
_delay_ms(100);
}
}
}
I'm trying to toggle an LED when I receive a certain character through the Bluetooth module (HC05).
I've written the USART library just like the datasheet but it doesn't seem to work (I'm only concerned with the initialization and receiving code since I'm working on a half duplex system so i don't need the transmition part).
I'm using Atmega32a with a 16MHz external crystal Oscillator.
Please tell me if you find anything wrong.
Thanks in advance.
Your Initialization is wrong.
Try this
void USART_Init(void){
UBRRL = TUBRR;
UBRRH = TUBRR >> 8;
UCSRB = (1<<TXEN)|(1<<RXEN);
UCSRC = (1<<UCSZ1)|(3<<UCSZ0);
}
This is the following initialization code provided in data sheet of atmega32
void USART_Init( unsigned int baud )
{
/* Set baud rate */
UBRRH = (unsigned char)(baud>>8);
UBRRL = (unsigned char)baud;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}
I know following datasheet is little overhead in beginning But eventually you will see all your answers are provided there.

setting an i2c register to high

I have this project that my boss asked me to do and the first step is to figure out how to set a given I2C register to high or low using the silicon lab library, if anyone knows any good sources for this type of problem please provide them thank you. The pic that I am using is the pic16f1823, I've already looked at the documentation of the pic but into only states how to read and write to an I2c.
I use this as a header file and seems to work well for PIC16F1827 which is basically the same as the 1823. It used the peripheral of the PIC. Just include in in any c file you want to use i2c in. Make sure you #define FOSC in order to calculate the correct baud rate. Also double check the port and tris assignments are correct for your device and make adjustments.
It uses polling instead of an interrupt. Uncomment the interrupt setup code and write an interrupt service routine to catch the interrupts.
#ifndef I2C_H
#define I2C_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Hi-Tech C I2C library for 12F1822
* Master mode routines for I2C MSSP port to read and write to slave device
* Copyright (C)2011 HobbyTronics.co.uk 2011
* Freely distributable.
*/
#define I2C_WRITE 0
#define I2C_READ 1
// Initialise MSSP port. (12F1822 - other devices may differ)
void i2c_Init(void){
// Initialise I2C MSSP
// Master 100KHz
TRISB2 = 1;
TRISB5 = 1;
SSP1CON1 = 0b00101000; // I2C Master mode
SSP1CON2 = 0b00000000;
SSP1CON3 = 0b00000000;
//SSP1MSK = 0b00000000;
SSP1ADD = I2C_BRG; // clock = FOSC/(4 * (SSPxADD+1))
//SSP1IE = 1; // enable interrupt
SSP1STAT = 0b10000000;
}
// i2c_Wait - wait for I2C transfer to finish
void i2c_Wait(void){
while ( ( SSP1CON2 & 0x1F ) || ( SSPSTAT & 0x04 ) );
}
// i2c_Start - Start I2C communication
void i2c_Start(void)
{
i2c_Wait();
SSP1CON2bits.SEN=1;
}
// i2c_Restart - Re-Start I2C communication
void i2c_Restart(void){
i2c_Wait();
SSP1CON2bits.RSEN=1;
}
// i2c_Stop - Stop I2C communication
void i2c_Stop(void)
{
i2c_Wait();
SSP1CON2bits.PEN=1;
}
// i2c_Write - Sends one byte of data
void i2c_Write(unsigned char data)
{
i2c_Wait();
SSPBUF = data;
}
// i2c_Address - Sends Slave Address and Read/Write mode
// mode is either I2C_WRITE or I2C_READ
void i2c_Address(unsigned char address, unsigned char mode)
{
unsigned char l_address;
l_address=address<<1;
l_address+=mode;
i2c_Wait();
SSPBUF = l_address;
}
// i2c_Read - Reads a byte from Slave device
unsigned char i2c_Read(unsigned char ack)
{
// Read data from slave
// ack should be 1 if there is going to be more data read
// ack should be 0 if this is the last byte of data read
unsigned char i2cReadData;
i2c_Wait();
SSP1CON2bits.RCEN=1;
i2c_Wait();
i2cReadData = SSPBUF;
i2c_Wait();
if ( ack ) SSP1CON2bits.ACKDT=0; // Ack
else SSP1CON2bits.ACKDT=1; // NAck
SSP1CON2bits.ACKEN=1; // send acknowledge sequence
return( i2cReadData );
}
#ifdef __cplusplus
}
#endif
#endif /* I2C_H */
Then you can use the higher level functions defined above to control a device, which is described in the datasheet of the slave device.
For example, to read from an eeprom:
#include <xc.h>
#define FOSC 16000000
#include "i2c.h"
unsigned char i2c_read_eeprom( unsigned char slaveaddress, unsigned char memaddress )
{
unsigned char data;
data = 123;
i2c_Start();
i2c_Address( slaveaddress, I2C_WRITE);
i2c_Write(memaddress);
if( SSP1CON2bits.ACKSTAT )
txstring("ACK!\r\n");
else txstring("nACK!\r\n");
i2c_Start();
i2c_Address( slaveaddress, I2C_READ);
data = i2c_Read(0);
i2c_Stop();
return data;
}

PIC to PIC UART communication to Blink the LED

I want to send a command by PIC12F1572 to another PIC12F1572 through UART
and in that I want to send a function which will blink the LED on the slave PIC.
I have done some code but I am somewhat confusing
can anyone help me here?
P.S- I am Using MPLAB X IDE v3.50
Master/Transmitter PIC12F1572:
#include <xc.h>
#include "main.h"
#include "config.h"
#include "TYPEDEF_Definitions.h"
#include "PIC_12_Timer0.h"
#include "PIC_12_UART.h"
#include "System_init.h"
#include "Pin_manager.h"
#include "LED.h"
#define _XTAL_FREQ 16000000
void main()
{
SYSTEM_Initialize();
//pin_config();
LATA = 0x00;
UART_Init(); //Initialize UART
// StartLedBlinkingWithColor(color);
TRISAbits.TRISA2 = 1; //make RA2 as input
while (1)
{
//LATAbits.LATA2 = 1;
uint8_t Var = 0x61;
//uint8_t Var = LATAbits.LATA2;
if(TXSTAbits.TRMT == 1)
{
UART_write(LED_Blink()); // is it possible?? or how it will be possible
// __delay_ms(1000);
}
LATAbits.LATA2 = 1;
}
}
void LED_Blink()
{
LATAbits.LATA2 = 1;
LATAbits.LATA5 = 1;
__delay_ms(1000);
LATAbits.LATA2 = 0;
LATAbits.LATA5 = 0;
}
RECEIVER/SLAVE PIC12F1572:
#include <xc.h>
#include "config.h"
#include "PIC_12F_GPIO.h"
#include "Led.h"
#include "Interruptmanage.h"
#include "PIC_12F_UART.h"
#include "PIC_12F_TIMER0.h"
#include "main.h"
void main( void)
{
uint8 data;
InterruptInit();
TIMER0_Init();
UART_Init();
InitLeds(); // here I init GPIO pin..no prb here
// SetLedOff();
/*-------------R E C E I V E R*------------*/
while (1)
{ // Endless loop
if (UART_DataReady() ) // I get prob here ..
{
PORTA = UART_ReadOneByte(); // read the received data, [how can I receive my Led_Blink() function??
LATAbits.LATA2 = 1;
//LATAbits.LATA2 = data;
//SendByteSerially(data);
}
}
}
There are a couple of things to consider:
You cannot "send a function" through the UART. Therefore, the LED_Blink() function needs to be on the receiver side. Before doing anything else, verify that the function works on the receiver side, without any UART interaction.
Next, you can define a protocol, which is basically deciding which byte values you send through the UART should trigger the LED_Blink() call on the receiver side. For example, if you decide to use the byte value of 42 to trigger a LED blink, your sender would call UART_write(42) and on the receiver side, you would have something like the following:
data = UART_ReadOneByte();
if (data == 42) {
LED_Blink();
}
So for Receiving data from UART and saving it in array and use the data to vlink nthe LED I Have done this code: Anyone interested can have a look
while (1)
{
if (EUSART_DataReady)
{
for (i = 0; i<FRAMESIZE; i++) //#define FRAMESIZE 19
{
RX_Buffer[i] = EUSART_Read();
if (RX_Buffer[i] == '\n') //check'\n' in the end of frame
break;
}
RX_Buffer[i] = '\n'; //append '\n' at the end of stoaring array for detection of frame
RX_Buffer[i+1] = '\0'; // End of an array
EUSART_WriteAnArrayOfBytes(RX_Buffer);
if(RX_Buffer[0]=='R' && RX_Buffer[FRAMESIZE-2] == '\n') //check for correct frame
{
LATAbits.LATA2 = 1;
__delay_ms(2000);
LATAbits.LATA2 = 0;
__delay_ms(1000);
}
}
}

Saving video as series of images opencv

This question is in continuation of error-in-opencv-code-for-motion-detection. The editted code works without any errors but the output video is not created,it is of zero bytes!What is wrong in this?Also,the bounding box created for motion detection never really captures the motion that is, it does not do what it originally claimed to do.Am I misunderstanding something about the objective of thie code?So, here are my questions:
How to rectify the creation and save the video?
What needs to be modified to detect motion and track it?
How to convert the video to a series of numbered jpg images from each frame and vice-versa.
Here is the code which you can work with to frame a video as a set of images.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cv.h"
#include <highgui.h>
#include "cxcore.h"
int main( int argc, char** argv )
{
CvCapture *capture = cvCaptureFromAVI("E:\\Myvideo.avi");
if(!capture)
{
printf("!!! cvCaptureFromAVI failed (file not found?)\n");
return -1;
}
int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
printf("* FPS: %d\n", fps);
IplImage* frame = NULL;
int frame_number = 0;
char key = 0;
while (key != 'q')
{
// get frame
frame = cvQueryFrame(capture);
if (!frame)
{
printf("!!! cvQueryFrame failed: no frame\n");
break;
}
// quit when user press 'q'
key = cvWaitKey(1000 / fps);
}
// free resources
cvReleaseCapture(&capture);
return 0;
}

Resources