Porting sketch from UNO to Pro Mini

First post and I need some help.

I have a sketch available on Github for a thermometer/hygrometer working on a UNO (I modified it to show Celsius). To finish the project I want to get it running on a Pro Mini so I can put it in an enclosure and finish it.

It has been several years since I started (and left it for quite a while) and I have fumbled my way to the following stage:

  • configured the Arduino app on Mac to work with the Pro Mini
  • got the Blink sketch uploaded and working
  • updated the libraries for the TFT and DHT22
  • recompiled the sketch and uploaded it to the Pro Mini
  • wired the mini to 5V (raw pin)
  • connected the power to the TFT and DHT

Now, I don’t know for sure how to modify the sketch and attach the sensor and screen digital connections as the pin numbering is clearly not the same. I assume that i just need to reassign the digital IOs in the sketch but what pins to use?

Is it OK to upload the UNO sketch here for advice?


Is it OK to upload the UNO sketch here for advice?

Not just allowed, but positively encouraged

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here

Do I zip it?

No, attach it to a new post

Here is the code but I got an error about exceeding 9000 characters so truncated the parts related to the calculations and display.

/* -----------------------------------
* Arduino Project Box LCD 
* temperature/humidity monitoring system
* by: cncartist - 04/25/2016
/* -----------------------------------
* Arduino UNO
* 1.8 tft lcd // ST7735 // tiny red thing
* dht22 digital temp sensor
* ---------------
* LED = LED    == 3.3V
* SCK = CSK    == 13
* SDA = MOSI   == 11
* AD  = DC     == 9
* RESET = RST  == 8
* CS  = CS     == 10
* GND          == GND
* VCC          == 5V
* ---------------
* tmp1 = +5v
* tmp2 = D2 [ 10K to pin1 ]
* tmp4 = gnd
* ---------------
* 3.3 aref not reliable w lcd draw
// ----------------------------------- */

// -----------------------------------
//text colors used
//color green - TFTscreen.stroke(20,255,20);
//color white - TFTscreen.stroke(255,255,255);
//color black - TFTscreen.stroke(0,0,0);
//color purple - TFTscreen.stroke(0,0,0);

// include libraries
#include <TFT.h>  // Arduino LCD library
#include <SPI.h>
#include <DHT.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8 
#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// -----------------------------------
// START declare variables
char sensorPrintout[4];

int tempVal;

float tempPrevF;
float tempPrevC;
float tempPrevLow;
float tempPrevHigh;

float humCurPrev;
float humCurPrevLow;
float humCurPrevHigh;

float tempLowest;
float tempHighest;
float humidCur;
float humidLowest;
float humidHighest;

int mathTestVal;
int mathTestVal2;
int mathTestVal3;
int mathTestVal4;

int mathTestHumid;
int mathTestHumidLow;
int mathTestHumidHigh;

int mathTestPrevF;
int mathTestPrevC;

int mathTestPrevHum;
int mathTestPrevHumLow;
int mathTestPrevHumHigh;
int mathTestPrevTempLowest;
int mathTestPrevTempHighest;

// END declare variables
// -----------------------------------

My suggestion was to attach it to a new post

Either use the Reply button rather than Quick Reply or use Quick Reply, enter your reply then preview. Either way the "Attachments and other options" link will be available below the editor window

Woops :frowning:

Sketch now attached :slight_smile:

text.txt (14.6 KB)

Comparing two pinout diagrams I think this is correct but not sure about some

13. SCK 17
11. MOSI. 15
10. SS. 14
9. SDA. A4
2. DATA. ????

What 'Pro Mini' do you have that uses pin numbers like 14,15,17 etc ?

All the 'Pro Minis' I have seen use the same pin numbering as a UNO, with the exception that a 'Pro Mini' has A6 and A7.

Miini or Micro?

Pro Mini

May be I looked at the wrong schematic. I will use this one that has the same pin numbering as on the board.
Can anyone help with tbe problem?
Do I simply wire the Pro Mini the same as the UNO , or do I have to modify the sketch?

ProMini8MHzv2.pdf (546 KB)

Promini is wired the same as an Uno, Same processor, same IO pinout.
D0 to D13 are all the same
A0 to A5 are all the same (they also function as D14 to D19).

Promini may also have A6, A7, which are analog input only and not available on the Uno.

Look up a pro mini pinout diagram, you seem to be numbering the pins from the physical connector instead of the arduino pin designations. There should not be any modification needed for the code.

Thanks for the clarification
The pinout diagram from www.theengineeringprojects.com threw me.

OK got it wired up and working. There is some strange behaviour, often when power is turned on the display shows only “zeros” for the temp and humidity and it doesn’t change. Other times it shows actual data.
Sometimes it boots up showing data and then, refreshes the screen and reverts to “zeros”.
It is sometimes stable showing live data.
It did this before with the UNO.
I need it to be a bit more reliable.
I am using the AM2320B sensor.
Anyone know why that might be?

got it wired up and working

Please post a schematic (a 'photo of a pencil drawing will do) as that image is useless in determining the wiring

What code are you using ?

Image wasn’t really to show hookup but the display.
The code is attached in post #5
Here is the creator’s schematic for the UNO, it is fairly low res. If it is no use I can sketch it if there are no obvious issues in the code.
[I should have added a link to creators project Arduino Project Box with locations for LCD/switch/wiring + closable wiring lid - Hangs on printer - Qidi / Flashforge Creator by cncartist - Thingiverse]



Now stuck showing zeros.
Could the sensor be faulty? Any way to test?

I think I will solder it up, might be dodgy breadboard connections.

Sensor board had no faulty joints.
Point to point wiring according to schematic.
3D printed a case and installed it with USB power and external reset switch. Sensor glued onto case rear.
Still have issue of getting it to start up consistently.
Is there a boot sequence in the code?

Have you tested simply reading the sensor and printing the values to the Serial monitor ?

How do I do that (sorry complete programming idiot here)?
Do I attach the FTDI and run the Serial monitor in the IDE or do I have to upload a sketch to the Pro Mini first?
The humidity reading from the DHT22 is way off compared to several other standalone devices I have (showing 70 vs 47).