Connect an ESP32 (Lolin32 Lite Dev Board) to a 7 pin SPI TFT Display ST7789 Driver - spi

I would like to connect my ESP32 (Lolin32 Lite Dev Board) to a "1.3 inch 7PIN SPI HD Full Color IPS TFT Display Screen ST7789 Drive IC 240*240". I am using the Arduino IDE.
I have not managed to find a ST7789 library for the ESP32. I have tried to port the Arduino_ST7789 library to the ESP32 to no avail (I am relatively new at embedded programming). I am currently writing my own library from scratch, but effort.
What code/libraries would I need to get started with the display?
My hardware connections are as follows
ESP32 -> Display
Pin GND -> GND
Pin 3.3V -> VCC
Pin 18 -> SCL
Pin 23 -> SDA
Pin 15 -> RES
Pin 13 -> DC
Pin 2 -> BLK

I figured out the solution, I wasn't able to use the Arduino_ST7789 library because i did not have the correct boards manager.
To get the correct manager go File->Preferences then scroll down to "Additional Boards Manager URLs" and add the following URL.
https://dl.espressif.com/dl/package_esp32_index.json
Note: If you have existing URLs don't delete them otherwise you will lose access. Add the board to your sketch by going Tools->Board->LoLin D32
Get the relevant libraries by downloading this https://github.com/adafruit/Adafruit-ST7735-Library as a .zip
Next add the library by going Sketch->Include Library->Add .ZIP Library...
Then go to File->Examples->Adafruit ST7785 ST7789 Library->Graphicstest
Use the following code above the setup function
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#define TFT_CS 5
#define TFT_RST 15 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 13
#define TFT_MOSI 23 // Data out
#define TFT_SCLK 18 // Clock out
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
float p = 3.1415926;
Sit back and enjoy some crazy displays

You can use the Hardware supported SPI as well. Initialize the display library like:
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
and adjust the SPI to your specific IO lines at startup (in setup()):#
SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI);
tft.init(240, 320); // Init ST7789 320x240

Related

Issue in implementing capacitive touch in PIC18F26K40 microcontroller using mTouch library

i currently working on PIC microcontroller. I have PIC18F26K40. I want to use CVD (Capacitive Voltage Divider) technique to implement capacitive touch button. I am using mTouch library of MCC (Microchip Code Configurator) library for that. I am doing same as per microchip documentation (links are here and here ). PIC is not detecting the touch. Here is my main method below:
void main(void)
{
// Initialize the device
SYSTEM_Initialize();
INTERRUPT_GlobalInterruptEnable();
INTERRUPT_PeripheralInterruptEnable();
LED_TRIS = OUTPUT;
while (1)
{
if(MTOUCH_Service_Mainloop())
{
/* Button API*/
if (MTOUCH_Button_isPressed(0))
LED_LAT = HIGH;
else
LED_LAT = LOW;
}
}
}
I have some doubts:
What is differential CVD.
What is driver shield. Do i need it?
Do i need to use two analog channels.
I have worked and tested CTMU mode of PIC18F26K22. Is there any way use CVD like CTMU.
If you have any solutions with or without library then let me know.
I am attaching some screenshot of my MCC configurations. Please go through it.
Help needed!
Note:
MPlab IDE: v5.50
Analog pin used for sensing: RB0
Programmer: PICKIT3
I came across your post whilst researching another issue with PIC mTouch on the same MPU you're using (or, rather the low voltage version, PIC18LF26K40). I am also using MPLAB X v5.50 with the mTouch plugin. Just wanted you to know that I was able to set up a single touch button with no problem on this chip, actually compiled and worked on the first try. So, you're on the right track!
You do not need to use the "driven shield" that is presented as an mTouch output (this is for improving signal integrity later when you're concerned about such things, see the various app notes on this). I used the "CS" (capacitive sensor) output only and it works fine.
This video helped me get started: https://www.youtube.com/watch?v=CCW3g9RqpZk
Hope this helps a bit.

GPIO interrupt for MSP430f2274

i am working on a project in msp430f2274 microcontroller. In my project i am trying to read an reed switch which is being connected to a GPIO pin at P2.3. Normally the pin will remain HIGH as it is being connected to pull up from the hardware. when once the switch is pressed/activated a LOW will come and it will trigger the Hardware. till here it is working fine. but now i want to read the other interrupt also, when it goes back to high. I have tried the interrupt type from low - high to high -low in ISR but still no efffect. please help.
i have added ISR from the code
static char x=0;
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1IES^=BIT2;
P1OUT^=(BIT0); // enrer the rest code for detection of door open or close.
P1IFG &= ~BIT2;
//P1IES&=~BIT2;
__bis_SR_register_on_exit(GIE+LPM0_bits); // Enter LPM3 on ISR exit
}
Just an idea, sry if this doesn't help.
You could use a timer that starts with the button click and triggers an interrupt when the button is released.

I'm trying to connect a Genius mouse to an Arduino using a PS2 mouse sketch, but it will not initialise the mouse

I have been using the mouse sketch at the bottom of this message (written by someone else) to try to get the motion data out of a PS/2 mouse. I have checked the specification for this mouse which says that it is PS/2 compatible. However, when I run it it appears to stop at the first line of mouse_init where it says, "mouse.write(0xff); // reset". This is a call to a function in ps2.h. ps2.h has been around since 2008 and has been used in a number of projects, so I assume it is okay, but I was wondering if there might be some peculiar features of USB mice connecting as PS/2 mice that this library was never designed to cope with. Does anyone have any experience that might shed some light on this?
I have been able to determine that mouse.write is changing the state of my Genius mouse, but it gets stuck at the point where the Mouse is supposed to bring the clock state low so that the host can proceed to transmit data. Before mouse.write starts the clock state is low, but it gets pushed high by the host a few lines into mouse.write and stays there. The mouse never pulls it low again. Any thoughts on what the trouble might be would be greatly appreciated.
#include <ps2.h>
/*
* an arduino sketch to interface with a ps/2 mouse.
* Also uses serial protocol to talk back to the host
* and report what it finds.
*/
/*
* Pin 5 is the mouse data pin, pin 6 is the clock pin
* Feel free to use whatever pins are convenient.
*/
PS2 mouse(6, 5);
/*
* initialize the mouse. Reset it, and place it into remote
* mode, so we can get the encoder data on demand.
*/
void mouse_init()
{
mouse.write(0xff); // reset
mouse.read(); // ack byte
mouse.read(); // blank */
mouse.read(); // blank */
mouse.write(0xf0); // remote mode
mouse.read(); // ack
delayMicroseconds(100);
}
void setup()
{
Serial.begin(9600);
mouse_init();
}
/*
* get a reading from the mouse and report it back to the
* host via the serial line.
*/
void loop()
{
char mstat;
char mx;
char my;
/* get a reading from the mouse */
mouse.write(0xeb); // give me data!
mouse.read(); // ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
/* send the data back up */
Serial.print(mstat, BIN);
Serial.print("\tX=");
Serial.print(mx, DEC);
Serial.print("\tY=");
Serial.print(my, DEC);
Serial.println();
// delay(20); /* twiddle */
}
Solved it. As it turns out the Genius mouse I brought is not backward compatible with PS/2 even though the specification says it is. They must have exchanged the sensor chip for one where the PS/2 capability was not present at some point. I now have another USB mouse which is doing the job I wanted perfectly.

Configuring PINB.4 and PINB.5 in AVR ATMega 169 to work as input pins and to enable pull up?

I want to configure two AVR butterfly boards in such a way that PORT D is an output port in the first one and two pins of this PORT D are connected to pins B.4 and B.5 of port B of the second AVR butterfly board. I also want to enable pull-ups on these port B pins. Is this configuration correct for the second AVR ? Is there something that i am missing?
//Init port pins
DDRB = 0x00;
PORTB |= 0X30;
//Enable pin change interrupt on PORTB
PCMSK1 = 0X30;
EIFR = 0XC0;
EIMSK = 0XC0;
SIGNAL(SIG_PIN_CHANGE1)-- Pin change interrupt of PIN B.4
{..}
SIGNAL(SIG_PIN_CHANGE2)-- Pin change interrupt of PIN B.5
{..... }
You have set up you PORT B correctly but it wouldn't hurt to improve your coding conventions a little.
DDRB&= ~(1<<PB0)|(1<<PB1);
PORTB|= (1<<PB0)|(1<<PB1);
Unless I am miss-understanding what your trying to accomplish, I don't think your interrupts are configured correctly.
PB4 and PB5 correspond to PCINT12 and PCINT13 respectively.
Since both correspond to Pin Change Interrupt Enable 1 you'll want to only have that pin enabled.
EIMSK = (1<<PCIE1);
You don't actually need to set EIFR unless your trying to manually trigger an interrupt. This register gets flagged automatically whenever a pin change occurs.
In PCMSK1 you want to set PCINT13 and PCINT12
PCMSK1 |= (1<<PCINT12)|(1<<PCINT13);
This enables interrupts on the corresponding pins.
Also SIGNAL is depreciated. #include avr/interrupt.h and use ISR.
ISR(PCINT1_vect){}
Both Pin changes will be handled by this vector.
Hope this clears things up a bit.

Setting sound output/input

I've been looking all over the web, but I don't know if it is possible: can a Cocoa Mac OS X app change the sound input/output device? If so, how come?
can a Cocoa Mac OS X app change the sound input/output device?
Yes, by setting the relevant Audio System Object property.
If so, how come?
Probably because the user might want to change the default input or output device from within an application, rather than having to jump over to the Sound prefpane before and after or use the Sound menu extra.
I know this is an old post but I've been struggling these days trying to find a way of changing the sound input/output device using code and I finally found how to do it. In case someone else runs into the same problem, here's the answer!
There's a command line utility called SwitchAudio-OSX (https://code.google.com/p/switchaudio-osx/) that allows you to switch the audio source from the terminal. It is open-source and you can find the latest version here: https://github.com/deweller/switchaudio-osx.
Anyway, you can use these lines to change the sound input/output device:
UInt32 propertySize = sizeof(UInt32);
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultInputDevice, propertySize, &newDeviceID); // To change the input device
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultOutputDevice, propertySize, &newDeviceID); // To change the output device
AudioHardwareSetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice, propertySize, &newDeviceID); // To change the system output device
Where newDeviceID is an instance of AudioDeviceID and represents the id of the device you want to select. Also, a list of all available devices can be obtained using this code:
AudioDeviceID dev_array[64];
AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propertySize, dev_array);
int numberOfDevices = (propertySize / sizeof(AudioDeviceID));