arduino pro micro gives error on power up

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
skypickle
 
Posts: 57
Joined: Thu Jun 22, 2017 8:11 am

arduino pro micro gives error on power up

Post by skypickle »

This code compiles and when uploaded works fine.

Code: Select all

/***************************************************
This sketch monitors a potentiometer and prints its output on the serial monitor.
It also monitors a button push and changes the display of text on a TFT screen
 ****************************************************/

#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"

// These are 'flexible' lines that can be changed
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8 // RST can be set to -1 if you tie it to Arduino's reset
#define POTENTIOMETER_PIN A0

const int buttonPin = 5; 
int buttonState = 0; 
int pageCount = 1; 
// Use hardware SPI (on micro, #14, #15, #16) and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  while (!Serial) { delay(10); }

  tft.begin();

  // read diagnostics
  uint8_t x = tft.readcommand8(HX8357_RDPOWMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDCOLMOD);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDDIM);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(HX8357_RDDSDR);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 

  //default page prints
  testText();
}

void loop() {

  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    pageCount=pageCount + 1;
     switch (pageCount)  {
      case 1:
      testText();
       break;
      case 2:
       testText2();
       break;
      default:
       pageCount = 0;
       break; 
      }
   } else {
    // nothing
   }
  
  Serial.println(analogRead(POTENTIOMETER_PIN));
  delay(100);
}


void testText()  {
//unsigned long testText() {
  tft.fillScreen(HX8357_BLACK);

  tft.setCursor(0, 0);

  tft.setTextColor(HX8357_RED);    
  tft.setTextSize(3);
  tft.println("       test 1");
  tft.println();
  tft.setTextColor(HX8357_GREEN);
  tft.setTextSize(2);
  tft.println("         first section\n");
  tft.println("-----this is the first----\n");
  tft.println("-----this is the second---\n");
  tft.println("-----this is the third----\n");
 
  tft.println();
  tft.println("-----------more-----------\n");
  tft.println("---------even more--------\n");
  tft.println("-----and there's more-----\n");
  tft.println();
  tft.println("-----but is there more?--\n\n");
  tft.println("         yes \n");
  tft.println("------------so------------\n");
  tft.println("-----------much-----------\n");
  tft.println("-----------more-----------\n");
  
}


void testText2()  {
//unsigned long testText() {
  tft.fillScreen(HX8357_BLACK);

  tft.setCursor(0, 0);

  tft.setTextColor(HX8357_RED);    
  tft.setTextSize(3);
  tft.println("       test 2");
  tft.println();
  tft.setTextColor(HX8357_GREEN);
  tft.setTextSize(2);
  tft.println("       a whole different page\n");
  tft.println("-----a first----\n");
  tft.println("-----a second---\n");
  tft.println("-----a third----\n");
 
  tft.println();
  tft.println("-----------none-----------\n");
  tft.println("---------even none--------\n");
  tft.println("---and there's  no more---\n");
  tft.println();
  tft.println("-----but is there more?--\n\n");
  tft.println("         no \n");
  tft.println("-----------not------------\n");
  tft.println("------------a-------------\n");
  tft.println("-----------bit------------\n");
  
}

If however I unplug the micro from usb, and then replug it, it does not run the sketch. The IDE shows this in red:

Code: Select all

java.io.IOException: --.SerialPortException: Port name - COM6; Method name - setEventsMask(); Exception type - Can't set mask.
	at processing.app.Serial.dispose(Serial.java:171)
	at processing.app.SerialMonitor.close(SerialMonitor.java:147)
	at processing.app.AbstractMonitor.suspend(AbstractMonitor.java:113)
	at processing.app.Editor$UploadHandler.run(Editor.java:2055)
	at java.lang.Thread.run(Thread.java:748)
Caused by: --.SerialPortException: Port name - COM6; Method name - setEventsMask(); Exception type - Can't set mask.
	at --.SerialPort.setEventsMask(SerialPort.java:279)
	at --.SerialPort.removeEventListener(SerialPort.java:1064)
	at --.SerialPort.closePort(SerialPort.java:1090)
	at processing.app.Serial.dispose(Serial.java:168)
	... 4 more
Please note, in the error message above, I had to edit out the term J S S C and replace it with two hypens because this site flagged that word as spam (weird).
Anyway
If I compile the code and reupload it , it works fine.

After some searching I read that the problem is contained entirely within Serial Monitor and the way it behaves when an Uno is disconnected from a computer. is there a fix?

User avatar
skypickle
 
Posts: 57
Joined: Thu Jun 22, 2017 8:11 am

Re: arduino pro micro gives error on power up

Post by skypickle »

Also prease note the above behavior occurs only with a pro micro board. An official arduino uno runs the sketch upon being plugged in - although nothing is output on the serial monitor.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”