Monday, May 21, 2018

One Cheap Arduino Nano Clone-o Plus one Cheap 1.8" TFT Display = An Entire Sunday!




Who can resist Amazon Prime Points?

Who can resist a cheap TFT display?  (I couldn't)

A million and one uses--as I develop my skills with Analog DIY and Digital hybrids I can justify all of this right?  (right???).

My goal this time: to design a simple DVM I can incorporate into audio gear. OF COURSE I can buy a DVM for like 25 cents that will probably work better.  And OF COURSE I already have  DVMs already. So why not stash one in my studio and use that.

(Answer: what fun would that be?)

Along the way, getting TFT displays going is an unfamiliar process for me, having never worked with a small display like this.....as well as understanding more about DACs, ADCs, and in general,  creating semi-precision applications--usually I just throw op amps at things and hope they work?

Anyway: these clones appealed due to their super low price ($6.50 US on a good day?), good online visibility and online .h libraries already written, like the Adafruit 7735 library

So just fire up an Arduino Nano clone, wire up the TFT, load in the Adafruit test sketch, and go?

Nope--Not that fast!

Here is the pix of my first Arduino clone….


I discovered the clones are.... "diff'rent".

To wit: some clone Arduinos don't use an FTDI USB chip you find in real Arduinos--the clono cuts corneros and uses cheaper USB chips.

So the drivers you have in your PC, used by the Arduino IDE to talk to a "real" Arduino chip, may not work with the clone board.

How this manifests: It's like you never hooked the Arduino up via USB at all--there is literally no USB port for the IDE to use to upload code to the board.

This is a first world problem.....

OK what to do: go to the Internet of course.

Turns out you can flip over the clone board and read the chipset used for USB, and google that to get the driver online?

But for my Nano clone, someone had scraped off the chip designation.  NICE!!!

From research online: this is the chip used to control USB on Clono-nanos but who scraped off the damn chip designation?

So I did what every tech does: I had to guess. Trial and error? I **hate** trial and error when fixing things!  From more reading: most clone Arduinos use CH340 USB chips.  The SOC layout of the USB chip looked like a CH340-CH341 so maybe that's what it is?  Just get the driver and go?

Driver is here  PLLUNNKKK!!!

(WARNING do not use this driver!  I took out the hyper link above!  It crashed my Mac!)

WTF???  I am using a Mac Sierra.  the chip's mfgr site says to use USB V1.3 for Mac. I downloaded that driver from the .cn site that will not be named and poof!  OS crashed.  mac unbootable. Yes, Elmo, the driver downloaded from the .cn vendor messed up an otherwise working Mac and made it unusable.  And maybe installed a keystroke reader and god only knows what else? VERY VERY NICE!

Forturnately I fix computers for a living so getting the Mac back wasn't that hard....the whole command + R thing.

Then a thorough anti-virus/anti malware pass. I  removed the butt driver and the Mac booted fine and appears to be secure again.

Back to square one--I still have the initial issue--how do I talk to the Arduino Clone?

Turns out--you need to get "the patched driver" for CH340/Mac OS sierra after removing the butt driver.

Time wasted: about an hour.  Arrg!

Now--with the right driver--now at least I can see Arduino no name-o Clone-o Nan-o and upload my code to it.  (OK no more o's)

Marvey. how do I wire the TFT?  How do I send proof of concept test code to it?

Trial and error pretty much? This time I felt it couldn't be avoided....

The TFT 1.8" device is a no-name unit with zero documentation. No links to the vendor's site. No vendor name silkscreened on the PCB I can use to track down  the pin-out designations.

And the pins didn't seem to match anything to do with SPI or MOSI really, but some of them say MOSI on them?  Hello?

I could go on and on.  But here is the last complaint: There was a QR code on the bag it came in, would that be a link to the mfgr's website maybe? but someone covered it up with a "made in China" sticker that I couldn't remove.  ARRRG!


The best link I could find, with pins that closely matched (but didn't exactly match) what I got on amazon, is here.

My OCD kicked in and I was determined to get this to work.  Who needs to do laundry?

After about 2 more hours I got this pin combo to work:

LED+  > hook to 3.3 V on the Nano clone board.
LED-  > GND (GND by the 6 pin header on the nano, not the GND down towards the other side of the board--the other GND on the nano clone didn't work)
CS  > CS
SCLK > SCK
MOSI > SDA (you knew that right?)
AO > DC (you knew that one too?)
Reset  > reset
VCC > 5V
GND > GND by 6 pin header.  There were 2 GND pins on the clone arduino Nano I used and the one of them didn't seem to be attached to anything.

There were other pins on the cheapo 1.8" TFT--some with very similar names--including one that tauntingly said "MOSI" that wasn't used at all when making the thing work.



(And of course the pin silkscreens on the TFT were on its underside, not the top.  So I had to write down a mirror image of how the pins are marked to figure it out.)

Once I got some life out of the board  I then modified the sample code provided by Adafruit with these pins and names:


#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

//how to wire from cheap-ass H340 based USB nano.
//vcc to 5v
//gnd to gnd by 6 pin header
//LED+ to 3.3 V
//LED- to GND by 6 pin header


#define cs    4  //there are 2 cs pins, don't use cs pin by the //LED+, wrong cs pin, but you knew that
#define sclk  5  // sck on TFT board
#define mosi  6  // sda connect on board, but you knew that
                     
#define dc    7 // ao connect on board, you knew that as well
#define rst   8 // reset, not 'rest'
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);


And it works!

The takeaway here: the super cheap .cn clones may not be worth it.  Stick to things (like TFT displays) that are well documented and offer at least support on a user forum.

it took me an entire Sunday to get the proof of concept you see here working, and I think if I just bought "the real deal" it might have only taken me a couple of hours.  What is my time worth, really?



As long as I am throwing stones: I am also pretty disappointed with Adafruit's GFX documentation. that's the library used to get graphics going on the board.

I thought since Adafruit is after hobbyist business (?) they would provide endless docs and code examples online, but I couldn't find their GFX tutorial at all, and their library documentation is powerfully short on useful examples. I guess it's way better than nothing, but their PDF needs to at least have working code examples in it.

What do I mean by this?

What the GFX Adafruit docs say:

void drawPixel(uint16_t x, uint16_t y, uint16_t color
); working code must look like this (only after instantiating an object called tft):


void tft.drawPixel(1, 1, 1 0xFFFF); Shouldn't I be able to just figure that out? Sure, and I did. But it wasn't as easy as it should have been.

UPDATE (5-24-18): Makerfocus, who read my less than favorable Amazon review of their Arduino clone's lack of drivers and scraped off SOC chip, contacted me several times to make sure I was OK.  
I should have had the common sense to Amazon message them as soon as I had issues with their driver vs. just assuming no one was out there and no one was willing to help. 

They were not only helpful and enthusiastic, I would venture to say they were downright sweet and kindhearted about making sure I had a fix.  Really!!! I will do business with these guys again...and I  have to remember all the time that the folks at the other end of the great global keyboard are humans, except for United's AI phone service?, trying to make a living, to stay sane and safe and get on with things--it's so easy to forget with this massive impersonal, loving and hateful system we all rely on, accurately called the "interweb", that we are DEVO....oh nevermind!





1 comment:

  1. Same trouble here, tryed everything. Contacted the seller, and they sent me more stuff that didn't work for me. Super sad ):

    ReplyDelete