Copy 50 serial readings to excel when I write some letter

Hi guys I need help with my job project, I need to copy 50 serial readings of my two nanoshield MAX 31856 to excel when I click in a letter in the serial monitor. I just have the code of the nanoshield:

#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>
#include <Adafruit_GFX.h>
#include "Nanoshield_Termopar.h"
#include <SPI.h>
#include "Nanoshield_LCD.h"

Nanoshield_Termopar termopar(52 , TC_TYPE_K, TC_AVG_OFF );
Nanoshield_Termopar termopar2(50, TC_TYPE_K, TC_AVG_OFF );

Nanoshield_LCD lcd;
#define XM A2

#define YP A3
#define YM 9
#define XP 8

#define TS_MINX 90
#define TS_MINY 92
#define TS_MAXX 906
#define TS_MAXY 951

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_RESET A4
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0


#define PRETO   0x0000
#define BRANCO 0xFFFF
#define AMARELO 0x0ff00
#define VERDE   0x07E0
#define VERMELHO 0xF800
MCUFRIEND_kbv tft;

#define MINPRESSURE 10
#define MAXPRESSURE 1000

bool error = false;
bool valor_botao1 = false;
bool valor_botao2 = false;

void telaInicial();
void setup() {

  Serial.begin(9600);
  termopar.begin();
  termopar2.begin();
  uint16_t ID = tft.readID();
  tft.begin(ID);
  tft.setRotation(1);


  telaInicial();
}

void loop() {
  TSPoint p = ts.getPoint();
  pinMode(XM, OUTPUT);
  digitalWrite(XM, LOW);
  pinMode(YP, OUTPUT);
  digitalWrite(YP, HIGH);
  pinMode(YM, OUTPUT);
  digitalWrite(YM, LOW);
  pinMode(XP, OUTPUT);
  digitalWrite(XP, HIGH);
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    p.x = tft.width() - (map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
  }


unsigned long tempoAtual = millis();
unsigned long tempoInicial = 0;

termopar.read(); 
 
tft.setTextColor(BRANCO);

  tft.setCursor(196, 150); 
  tft.print(termopar.getExternal());
  Serial.println (termopar.getExternal());
  Serial.println ("");

  termopar2.read();
  tft.setTextColor(BRANCO);
  tft.setCursor(196, 30); 
  tft.print(termopar2.getExternal());
  Serial.println (termopar2.getExternal());
  Serial.println ("");
  delay (1000);
 
  Serial.println (""); 
  Serial.println ("");
  Serial.println ("");

   criarBotao(186, 130, 125, 115, "", PRETO);
   criarBotao(186, 10, 125, 115, "", PRETO);
  criarBotao(20, 10, 125, 115, "", PRETO); 
  criarBotao(20, 130, 125, 115, "", PRETO);
 escreveEstado(32, 50, "Temp_1", BRANCO); 
  escreveEstado(32, 170, "Temp_2", BRANCO);

if (tempoAtual - tempoInicial >= 5000){
  if (p.y > 10 && p.y < 105) {
    if (p.x > 164 && p.x < 303) {
  tft.setTextSize(2);
      tft.setTextColor(BRANCO);
   tft.setCursor(196, 150);
    tft.print(termopar2.getExternal());
  delay (1000);
 }
}
}
if (tempoAtual - tempoInicial >= 5000){
 if (p.y > 10 && p.y < 105) {
    if (p.x > 44 && p.x < 175) {
  tft.setTextSize(2);
      tft.setTextColor(BRANCO);
   tft.setCursor(196,30);
    tft.print(termopar2.getExternal());
  delay (1000);
    }
}
}
}                                                         
void telaInicial() {
  tft.setRotation(3);
  tft.fillScreen(BRANCO);

  criarBotao(186, 130, 125, 115, "", PRETO);
  criarBotao(186, 10, 125, 115, "", PRETO);
  criarBotao(20, 10, 125, 115, "", PRETO); 
  criarBotao(20, 130, 125, 115, "", PRETO); 
  
  escreveEstado(32, 50, "Temp_1", BRANCO);
  escreveEstado(32, 170, "Temp_2", BRANCO);
  escreveEstado(140, 30, "Ext:", AMARELO);
  escreveEstado(140, 60, "Int:", AMARELO);
  escreveEstado(140, 150, "Ext:", AMARELO);
  escreveEstado(140, 180, "Int:", AMARELO);
}

void escreveEstado(int posx, int posy, String texto, int cor) {
  tft.setCursor(posx, posy);
  tft.setTextColor(cor);
  tft.setTextSize(2);
  tft.print(texto);
}

void criarBotao(int posx, int posy, int largura, int altura, String texto, int cor) {
  tft.fillRect(posx, posy, largura, altura, cor);
  tft.drawRect(posx, posy, largura, altura, PRETO);
  tft.setCursor(posx + 12, posy + 1000);
  tft.setTextColor(BRANCO);
  tft.setTextSize(3);
  tft.print(texto);
}

void atualizarBotao(int posx, int posy, int cor) {
  tft.fillRoundRect(posx, posy, 210, 48, 5, cor);
  escreveEstado(295, posy + 14, valor_botao1 ? "" : "", cor == VERDE ? BRANCO : PRETO);
}

That's not going to be very straightforward.

If I had to do this, I'd probably start from Excel, create a button and a VBscript action behind that, and then use that to acquire input from the appropriate COM port. Or maybe (even better) run a python script that captures the serial port output to a .csv file and then open that in Excel.

The Arduino IDE Serial Monitor isn't very suitable for interfacing with other applications.

1 Like

Yes I am trying to do this in phyton but it's going too hard

Just one more question, can program arduino not with c++ but with python?

Depends on the Arduino board. Some of the more advanced ones can run python scripts. What board are you using?

Arduino Due R3

But I have: Uno, Mega and Nano

With those, I'd look at turning the scenario around, and only transmitting from the Arduino the block of 50 values when you push a button wired to the Arduino. Set up Excel to receive from Serial (there's a tool for that, search here on the forum for Excel Serial, you should find it).

2 Likes

I don't think any of those boards will run micropython.

I also agree with @camsysca.
If you really want to start the data transfer process from the PC instead of the Arduino, I'd suggest triggering it by sending a command to the Arduino over UART and then have the Arduino respond by sending the 50 values.

1 Like

Thanks so much guys for helping me! @rsmls @camsysca

I see you've also asked this in another area - "Portuguese" - that's generally frowned on, as it duplicates effort.

The Microsoft 365 version of Excel has an add-in "Microsoft Data Streamer for Excel".

You have to add it in the "Options" menu:

2 Likes

Thanks, John, I've used similar addins long ago, but couldn't for the life of me remember what this one is called. Good to see that it's been 'grafted' to the Microsoft product.

Another possible alternative is this project maintained by an Arduino Forum member:

I haven't used it, but I know it is popular in the community.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.