How to fix Avrdude error when uploading to Nano - avrdude

I get this error:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
When I upload this code to my Nano:
#include <Servo.h>
Servo myservo;
int potpin = A0;
int val;
void setup() {
myservo.attach(9);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}
The Arduino help center says I might have selected the wrong board and port. So I reselected the Nano board and put in COM3. I also reinstalled the CH340 driver as my Arduino is a clone. I’ve tried reuploading and restarting but nothing seems to work and I get the same error. Anyone know how to fix this?
Any help is much appreciated.

Related

ESP32 - Connection to MCP23009. Can't get the OUTPUT to HIGH even if the connections returns succesful ( 0 )

I was trying to get an ESP32 working with I2C and because I had it around I took a MCP23009. Schmeantic is in the Image Image
My Code is the following :
#include <Wire.h> // specify use of Wire.h library.
#define MCPAddress 0x20 //I2C Address
#define IO_DIR_REG 0x00 // The Output Register
#define GPIO_REG 0x09 // The GPIO Register
#define IOCON 0x05 // Settings
#define SEQOP_REQ 0b00100000 // Disable address increment
#define I2C_SDA 21
#define I2C_SCL 22
int error;
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("Starting Wire");
Wire.begin(I2C_SDA, I2C_SCL);
Wire.setClock(100000); //Frequenz
Wire.beginTransmission(MCPAddress); // Check if connection succesfull
error = Wire.endTransmission();
if(error == 0){
Serial.println("Success");
}else{
Serial.println("Failure: ");
Serial.print(error);
}
//Serial.println("Disable Auto-Address increment!");
//writeBlockData(IOCON,SEQOP_REQ); //Experimental, didn't make it work
Serial.println("Setting Outputs!");
writeBlockData(IO_DIR_REG,0x00);
Serial.println("Writing LOW!");
writeBlockData(GPIO_REG,0x00);
}
void loop()
{
Serial.println("Writing HIGH!");
writeBlockData(GPIO_REG,0b11111111);
delay(3000);
Serial.println("Writing LOW!");
writeBlockData(GPIO_REG,0b00000000);
delay(3000);
}
int writeBlockData(uint8_t cmd, uint8_t val)
{
Wire.beginTransmission(MCPAddress);
Wire.write(cmd);
Wire.write(val);
delay(10);
return Wire.endTransmission();
}
It's fairly simple and the connections works as I get only 0 when I read Wire.endTransmission() but the LEDs never turn High. No matter what I do. Here is the Datasheet from the MCP http://ww1.microchip.com/downloads/en/DeviceDoc/20002121C.pdf
If anybody sees my mistake I would really appreciate it ! I am fairly new to work with I2C so I dont really see it. Even working with a Arduino Library didnt work.
Thanks and greetings !
Well, I didn' read the whole datasheet. The MCP has open drain outputs so turning around the diodes and put the other end into Vdd fixed it.

Why does my lcd console turn off if I let the imx6 board stay idle for 10 minutes?

I'm new to imx6 and yocto bsp and on exploring I found that the lcd console goes off after exactly 12 minutes. There seems to be no mention of this in the source code in yocto if there are no functions that turn off the display how could it go off?
I did some digging and found that yocto provides a wait mode which is meant to save power. I function I found in cpuidle-imx6sl.c as below but there is no mention of disabling lcd
static int imx6sl_enter_wait(struct cpuidle_device *dev,
struct cpuidle_driver *drv, int index)
{
int mode = get_bus_freq_mode();
imx6_set_lpm(WAIT_UNCLOCKED);
if ((mode == BUS_FREQ_AUDIO) || (mode == BUS_FREQ_ULTRA_LOW)) {
/*
* bit 2 used for low power mode;
* bit 1 used for the ldo2p5_dummmy enable
*/
if (psci_ops.cpu_suspend) {
psci_ops.cpu_suspend((MX6SL_POWERDWN_IDLE_PARAM | ((mode == BUS_FREQ_AUDIO ? 1 : 0) << 2) |
(ldo2p5_dummy_enable ? 1 : 0) << 1), __pa(cpu_resume));
} else {
pwr_ctrl_off();
imx6sl_wfi_in_iram_fn(wfi_iram_base, (mode == BUS_FREQ_AUDIO) ? 1 : 0,
ldo2p5_dummy_enable);
}
} else {
/*
* Software workaround for ERR005311, see function
* description for details.
*/
imx6sl_set_wait_clk(true);
cpu_do_idle();
imx6sl_set_wait_clk(false);
}
imx6_set_lpm(WAIT_CLOCKED);
return index;
}
I expect to find a function in the kernel source that disables lcd and also has a timer that measures exactly 10 minutes for lcd off. where can I find these?
You are probably seeing the console blanking timeout after 10 minutes, which turns off the display. To check the timeout value:
$ cat /sys/module/kernel/parameters/consoleblank
600
To disable it permanently, add consoleblank=0 to the kernel commandline. For example by editing your U-Boot environment.
You can find the code, that is responsible for this in drivers/tty/vt/vt.c.
Please try this command to force screen to get out of the sleep mode :
echo 0 > /sys/class/graphics/fb0/blank

Problem AVR stuck and program counter lost ...?

I am facing a strange behavior i am working on project using ATMEL MCU (ATMEGA328p) with huge amount with strings so i stored it in flash memory and during run time i read it from flash memory and send it via UART.
i don't know if this the problem or not because i was using the same technique before in other projects but what is different here the amount of strings larger than before.
void PLL_void_UART_SendSrting_F(U8_t* RXBuffer,const char * str , U8_t UART_No)
{
unsigned int _indx=0;
memset(RXBuffer,'\0', A9G_RX_Index); // Initialize the string
RXBuffer[A9G_RX_Index-1]='\0';
// cli();
while((RXBuffer[_indx]=pgm_read_byte(&(*str))))
{
str++;
_indx++;
_delay_ms(5);
}
// sei();
PLL_void_UART_SendSrting(RXBuffer,0);
}
But after awhile the whole program stuck and even after doing hard reset , to work again i should unplug and plug the power again.
Notes :-
- I am sure that hard reset working
- I am using timers in background as system tick .
The code is unsafe; you do nothing to prevent a buffer overrun.
Consider the safer, and simpler:
void PLL_void_UART_SendString_F( U8_t* RXBuffer, const char* str, U8_t UART_No )
{
unsigned index = 0 ;
RXBuffer[A9G_RX_Index - 1] = '\0' ;
while( index < A9G_RX_Index - 1 &&
0 != (RXBuffer[index] = pgm_read_byte( &str[index] )) )
{
index++ ;
}
PLL_void_UART_SendSrting( RXBuffer, 0 ) ;
}
Even then you have to be certain RXBuffer is appropriately sized and str is nul terminated.
Thank you for support
I found the issues, it was because watch dog timer keep the MCU in restart mode even when i press the hardware rest. this is because, i was considering all registers,flags back to its default value after rest.WDT Block Digram
i was doing that in code when MCU start execution the code like that :
U8_t PLL_U8_System_Init()
{
static U8_t SetFalg=0;
PLL_void_TimerInit(); // General Timer Initialize
PLL_WDT_Init(); // Initialize WDT and clear WDRF
wdt_enable(WDTO_8S); // Enable WDT Each 2 S
........
}
but once WDT occurred and rest the program then CPU found WDRF flag is set so it keep in rest for ever since i did power rest.
Solution
i have to clear WDT timer once program start first, before execute any code and its work
U8_t PLL_U8_System_Init()
{
static U8_t SetFalg=0;
PLL_void_TimerInit(); // General Timer Initialize
PLL_WDT_Init(); // Initialize WDT and clear WDRF
wdt_enable(WDTO_8S); // Enable WDT Each 2 S
........
}
this is what written in data sheet
Note:  If the Watchdog is accidentally enabled, for example by a runaway pointer or
brown-out condition, the device will be reset and the Watchdog Timer will stay enabled. If
the code is not set up to handle the Watchdog, this might lead to an eternal loop of timeout resets. To avoid this situation, the application software should always clear the
Watchdog System Reset Flag (WDRF) and the WDE control bit in the initialization
routine, even if the Watchdog is not in use.

GLib signal connect works with webkitgtk but not webkitgtk2

I am working on a web browser for fun and ran into this problem.
This works:
#include <webkit/webkit.h>
void init() {
GtkWidget *web_view = webkit_web_view_new();
g_signal_connect(
G_OBJECT(GTK_WIDGET(this->web_view)),
"notify::progress",
G_CALLBACK(LoadChangedProxy),
NULL);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(this->web_view), "http://google.com");
}
void LoadChangedProxy(GtkWidget *view, GParamSpec *pspec, gpointer p) {
puts("LOADING");
}
In this case the callback is never called:
#include <webkit2/webkit2.h>
void init() {
GtkWidget *web_view = webkit_web_view_new();
g_signal_connect(
G_OBJECT(GTK_WIDGET(this->web_view)),
"notify::estimated-load-progress",
G_CALLBACK(LoadChangedProxy),
NULL);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(this->web_view), "http://google.com");
}
void LoadChangedProxy(GtkWidget *view, GParamSpec *pspec, gpointer p) {
puts("LOADING");
}
I was attempting to use webkitgtk2 initially and was really hitting my head against the wall. I switched to the older webkitgtk1 header and api and it magically started working. I have not idea what would cause this, additionally no errors are printed to stderr or stdout (eg. attempting to connect to a signal that an object does not have).
Any suggestions out there? There is surprisingly little documentation on g_signal_connect, from glib. All I know has come from looking at some gnome app source code.
Edit:
I have found that using "notify::progress" signal identifier in the webkitgtk2 case, the callback works. However I then cannot use either webkit_web_view_get_progress() or webkit_web_view_get_estimated_load_progress() to read the progress value to display it.
The symptoms are strange enough that I can only think of one explanation: you are still linking with webkit-gtk. With trivial code like this you didn't happen to hit linking problems but of course the new signals wouldn't be there either.

How can you get Eclipse CDT to understand MSPGCC (MSP430) includes?

I'm using Eclipse and CDT to work with the mspgcc compiler, it compiles fine, but the code view highlights all my special function registers as unresolved.
I've made a C project where the compiler is "msp430-gcc -mmcu=msp430x2012", and that's set to look for includes in /usr/msp430/include/. I've set the linker to "msp430-gcc -mmcu=msp430x2012", and that's set to look fo libraries in /usr/msp430/lib/. I've set the assembler to "msp430-as". I've told eclipse it's making an elf and I've disabled automatic includes discovery to not find the i686 libraries on my linux box (stupid eclipse!).
Here's the code:
#include <msp430.h>
#include <signal.h> //for interrupts
#define RED 1
#define GREEN 64
#define S2VAL 8
void init(void);
int main(void) {
init(); //Setup Device
P1OUT = GREEN; //start with a green LED
_BIS_SR(LPM4_bits); //Go into Low power mode 4, main stops here
return(1); //never reached, surpresses compiler warning
}
interrupt (PORT1_VECTOR) S1ServiceRoutine(void) {
//we wake the MCU here
if (RED & P1IN) {
P1OUT = GREEN;
} else {
P1OUT = RED;
}
P1IFG = 0; //clear the interrupt flag or we immidiately go again
//we resume LPM4 here thanks to the RETI instruction
}
void init(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
/*Halt the watchdog timer
P1DIR = ~S2VAL; //Set LED pins as outputs and S2 as input
P1IES = S2VAL; //interrupt on High to Low
P1IE = S2VAL; //enable interrupt for S1 only
WRITE_SR(GIE); //enable maskable interrupts
}
All the variables defines in the mspgcc includes such as P1OUT and WDTCTL show up in the problems box as "not resolved", but remember it builds just fine. I've even tried explicitly including the header file for my chip (normally msp430-gcc does this via msp430.h and the -mmcu option).
I resolved this issue by explicitly including the msp430g2553.h file
#include <msp430g2553.h>
I resolved the issue by following the instructions here