-
some infos about the I2C from the IC doc
I2C Serial Interface
The HT16K33 includes an I2C serial interface. The I2C bus is used for bidirectional, two-line communication between different ICs or modules. The two lines are a serial data line (SDA) and a serial clock line (SCL). Both lines are connected to a positive supply via a pull-up resistor. When the bus is free, both lines are high. The output stages of devices connected to the bus must have an open-drain or open-collector to perform a wired and function. Data transfer is initiated only when the bus is not busy.
[...]
START and STOP Conditions
• A high to low transition on the SDA line while SCL is high defines a START condition.
• A low to high transition on the SDA line while SCL is high defines a STOP condition.
• START and STOP conditions are always generated by the master. The bus is considered to be busy after the START condition. The bus is considered to be free again a certain time after the STOP condition.
• The bus stays busy if a repeated START (Sr) is generated instead of a STOP condition. In this respect, the START(S) and repeated START (Sr) conditions are functionally identical.there is no busy pin on the driver board.
i was thinking to read B6 and B7 to know if it's busy... (as read in the doc)
If you digitalRead a pin, without a pinMode, you reset the pin in input :(
I've tried.
it freeze the display and add to upload a new firmware few time after (is it the cause.. i can't said) -
Gorgeous @allObjects!
it works pretty well, have to try it more.
Sometime pb persisting even with the tries...
I definitively will try with the scotchy diode...My crappy solution seemed effective but it was an evidence there was a better, nicer code structure to write to do this.
it seems if it catchs an error even with the tries it fail to initialize the display...
never mind i use your "boot sequence"just a small misspelling throw rather than trow (i'm unfamiliar with this command).
Thanks again.
It's nice codeI do not see a reset command in the doc
therefore i remove the first function (res). ;)é.
ps: clearInterval() was seen in a forum post about timeout
var ini = function() { // first require("Font4x6").add(Graphics); // initialisation I2C console.log("setup I2C"); I2C1.setup({scl: B6,sda: B7}); /* rajouter les init de connexion pour le display */ console.log("init programme affichage matrice v2.2 - éric choisy ©2019"); console.log("mém. utilisée: "+Math.round(process.memory().usage/process.memory().total*100)+"%"); } , osc = function(tries) { if (tries>0) { // third w/ retries try { console.log("turn OSC ON"); digitalPulse(LED2,1,20);//verte I2C1.writeTo(0x70, 0x21); // turn on oscillator setTimeout(don,250,2); } catch(e) { console.log(e); setTimeout(osc,250,--tries); digitalPulse(LED1,1,20);//rouge } } else throw "Unable to turn osc on"; } , don = function(tries) { if (tries>0) { // fourth w/ retries try { console.log("turn display ON"); digitalPulse(LED2,1,20);//verte I2C1.writeTo(0x70, 0x81); // display on setTimeout(lum,250,2); } catch(e) { console.log(e); setTimeout(don,250,--tries); digitalPulse(LED1,1,20);// rouge } } else throw "Unable to turn display ON"; } , lum = function(tries) { if (tries>0) { // fifth w/ retries try { console.log("set brightness"); digitalPulse(LED2,1,20);//verte I2C1.writeTo(0x70, 0xE0 | 0); // luminosité 0-15 setTimeout(envoieMatrice, 1000); } catch(e) { console.log(e); digitalPulse(LED1,1,20);//rouge setTimeout(lum,250,--tries); } } else throw "Unable to set brightness"; }; const onInit = function() { ini(); osc(3); // starts the chain \: };
i added led pulse to have visual feedback without a console...
-
ok understood! :)
i've got only one module... i keep in mind to remove the resistors (not on last) if i need to chain modules.
I do not work with flipdot matrix for this project (too deep, too expensive, no more flipdot module on sale :( ) just a big 60mm led matrix, with a ldr to adjust brightness and a pot for speed scroll text. -
i tried in a dirty way by adding some time in each command (a blank loop) and a try catch.
i've got less error.
sometime (1 in 5 switch on) there is no error but display does not start.
When i unplug/plug i lost the connexion therefore i do not receive the error... but i blink the led in the main program and it blink....
show you my ugly codeconst onInit = function() { clearInterval(); clearWatch(); pinMode(B6, 'opendrain'); pinMode(B7, 'opendrain'); require("Font4x6").add(Graphics); /* rajouter les init de connexion pour le display */ console.log("init programme affichage matrice v2.2 - éric choisy ©2019"); console.log("mém. utilisée: "+Math.round(process.memory().usage/process.memory().total*100)+"%"); // initialisation I2C console.log("setup I2C"); I2C1.setup({scl: B6,sda: B7}); // rouge try { console.log("try OSC ON"); I2C1.writeTo(0x70, 0x21); // turn on oscillator } catch(e) { I2C1.setup({scl: B6,sda: B7}); setTimeout(function() { console.log("try again 0x21"); try { I2C1.writeTo(0x70, 0x21); // turn on oscillator } catch(e) { console.log("does not init",e); } }, 250); } // init suite I2C for (var i=0; i<10000; i++) { // } try { console.log("try display ON"); I2C1.writeTo(0x70, 0x81); // display on } catch(r) { digitalPulse(LED1,1,20); //rouge for (i=0; i<10000; i++) { // } console.log("try again display ON"); I2C1.writeTo(0x70, 0x81); // display on } digitalPulse(LED2,1,20);//verte try { console.log("try brightness"); I2C1.writeTo(0x70, 0xE0 | 0); // luminosité 0-15 } catch(r) { digitalPulse(LED1,1,20); //rouge for (i=0; i<10000; i++) { // } console.log("try again brightness"); I2C1.writeTo(0x70, 0xE0 | 0); // luminosité 0-15 } digitalPulse(LED2,1,20);//verte setTimeout(envoieMatrice, 1000); };
-
@Robin
i give you more off my onInit()const onInit = function() { clearInterval(); clearWatch(); pinMode(B6, 'opendrain'); pinMode(B7, 'opendrain'); require("Font4x6").add(Graphics); /* rajouter les init de connexion pour le display */ // initialisation I2C I2C1.setup({scl: B6,sda: B7}); // rouge try { I2C1.writeTo(0x70, 0x21); // turn on oscillator } catch(e) { I2C1.setup({scl: B6,sda: B7}); setTimeout(function() { console.log("try again"); try { I2C1.writeTo(0x70, 0x21); // turn on oscillator } catch(e) { console.log("does not init",e); } }, 500); } console.log("init I2C"); // init suite I2C I2C1.writeTo(0x70, 0x81); // display on I2C1.writeTo(0x70, 0xE0 | 0); // luminosité 0-15 digitalPulse(LED2,1,20); setTimeout(envoieMatrice, 2000); };
and the output.
It does not loop
it try once as in the code
if i well understand, it fail on the first communicationinit I2C Uncaught InternalError: Timeout on I2C Write BUSY at line 1 col 541 ... I2C'),I2C1.writeTo(112,129),I2C1.writeTo(112,224),digitalPu... ^ in function called from system try again does not init InternalError: InternalError: Timeout on I2C Write BUSY >
-
Hello @allObjects M...
a/ i power the board and the display with usb from my macbook. I've tried with a 700mA phone charger, it inconsistently... After some time unplugged, when i plug the circuit with 5v, it does not initialize at first time... have to switch off/on (plug/unplug) few time and the display start. (as an old car or a cold engine that need a starter)
The backpack is supposed to work with a Feather (from adafruit) that work at 3.3v level.b/ not sure to understand what you mean (sorry)
c/ no c/
d/ i've tried
pinMode(B6, 'opendrain'); pinMode(B7, 'opendrain');
not better.
e/ I'll try tomorrow. I think i have a plastic bag full of these black diode... (i used it to stepdown current for led...is it the same?) (dont remember the ref... N4007 (in smd and old fashion black cylinder?)
thanks for your advice...
-
On an arduino there is no pullup resistor to add to circuit.
i tested with an other backpack, same result.
some time it works, sometime not.i tried with a try catch and resend a I2C.setup() (read it in the forum) in the resend with no more result.
try { I2C1.writeTo(0x70, 0x21); // turn on oscillator } catch(e) { I2C1.setup({scl: B6,sda: B7}); setTimeout(function() { console.log("try again"); try { I2C1.writeTo(0x70, 0x21); // turn on oscillator } catch(e) { console.log("does not init",e); } }, 100); }
other idea?
is there a way to loop on a init phase 'til it works? (a loop on the "try catch")? -
Hello,
i'm working with a pico and an Adafruit 8x8 matrix backpack (HT16k33).
I setup the I2C and initialize the displayI2C1.setup({scl: B6,sda: B7}); I2C1.writeTo(0x70, 0x21); // turn on oscillator I2C1.writeTo(0x70, 0x81); // display on
Some time (i'm unable to find a recurrent way, it come on a software upload or a switch on) the display does not start, with an I2C timeout (in the console)...
I've tried with decay for writing command..
same prob.I2C1.setup({scl: B6,sda: B7}); setTimeout(function() { I2C1.writeTo(0x70, 0x21); // turn on oscillator I2C1.writeTo(0x70, 0x81); // display on }, 500);
Any idea?
It is not a wiring pb (cause most of the time it work)thanks for yopur help
-
i've written something like that
var reponse= {trame:"",longueur:0}; s.setup(9600,{rx:B6, tx:B5}); s.on('data', function(data) { reponse.trame+= data; if (reponse.trame.length >= reponse.longueur) { switch (reponse.trame.charCodeAt(1)) { case 0x01: // status console.log("status:",reponse.trame.charCodeAt(3)); break; case 0x09: // status console.log("check Drive:",reponse.trame.charCodeAt(3)); break; case 0x12: //Check the total numbers of audio in all folders(12) console.log("nbr total audios:",(reponse.trame.charCodeAt(3)<<8 ^ reponse.trame.charCodeAt(4))); break; case 0x0C: //Check the total audios(0C) console.log("nbr total audios:",(reponse.trame.charCodeAt(3)<<8 ^ reponse.trame.charCodeAt(4))); break; case 0x0D: //current audio console.log("nom fichier audio:",reponse.trame.charCodeAt(3),reponse.trame.charCodeAt(4)); break; case 0x24: //duration audio console.log("Duréé: "+reponse.trame.charCodeAt(3)+"H "+reponse.trame.charCodeAt(4)+"mn "+reponse.trame.charCodeAt(5)+"s"); break; default: break; } } });
and each command sent, fill the
reponse.longeur
with the appropriate value...function Duration() { var command = [0xAA, 0x24, 0x00, 0xCE]; // Return: AA 24 03 hour minute second SM reponse.longueur = 7; reponse.trame = ""; s.write(command); }
Not Tested
Thanks for your help @allObjects.
-
-
i give you an example of a frame
//Check Playback Status(01) //Command: AA 01 00 AB let command= [0xAA,0x01,0x00,0xAB]; s.write(command) //Return: AA 01 01 Playback status SuM
if i've read and kept the good part in the gps module, it use an object and fill the "line" until it's more than 80chars or until \n char.
var gps = {line:""}; serial.on('data', function(data) { gps.line += data; });
i do not have this '\n' in the frame module.
the length is not always the same. between 5 and 7 chars.
The last char is always a sum of the values sent...
I could :
evaluate continiously the frame to know when it is end (the sum)
or
evaluate the second char received to determine the length of the frame (the command),
or
anticipate the length (5,6,7) of the response by the command sent.'Status', send back 5 chars
'duration of the current audio', send back 7 chars.thanks
i'll try.
-
Hello Markus,
a Happy new Year.i've found that in the forum and it do the job as i expect.
console.log("hex:",d.charCodeAt().toString(16));
the module send some char and the last one is the SUM of the transmitted string.
i wrote something like that (i did not test it on the espruino)let sum=0; let buf = new Uint8Array(); function checkAnswer(buff) { console.log(buff.toString(16)); switch (buff[1]) { case 0x01: // status console.log("status:",buff[3]); break; case 0x0C: //total audios console.log("total audios:",buff[3],buff[4]); break; case 0x0D: //current audio console.log("current audio:",buff[3],buff[4]); break; default: break; } // reset first buffer buf = new Uint8Array(); } s.setup(9600,{rx:B6, tx:B5}); s.on('data', function(d) { console.log("hex",d.charCodeAt().toString(16).toUpperCase()); let nd = d.charCodeAt(); buf.push(nd); sum+= nd; if (sum == nd && buf.length >1) { // fin de la transmission buf.pop(); // efface le sum du buffer sum = 0; checkAnswer(buf); } });
regards
-
Hello,
i'm working with Voice module from DFRobotif i use an array of command i'm supposed to receive some datas
i'm trying to convert the data in hexa value...
when i'm trying.toString(radix)
, console displays always the same char, not bin or oct or hex value...sorry, where i'm wrong?
s.setup(9600,{rx:A8, tx:B7}); s.on('data', function(d) { console.log(d.toString(2),d.toString(8),d.toString(16)); });
it display
ª ª ª $ $ $
-
@opichals done
thanks. -
Hello,
i find a strange behaviour of the chrome ide with a pico with v2.00 firmware
If i use alet
in a switch case block, IDE generate an errorError: Line 15: Unexpected token let
i'm not not sure why it's wrong?
in an html page with the code it does not generate error
and for my point of view i could legaly use alet
in the block
if i upload the code in the espruino, it works.
in a more complexe prog, it generate error in the code and nothing works (i've took some time to understand the prob)
if i change thelet
for avar
no error anymore and code run on the espruinolet phrase= ""; function test() { let tire = 7; switch (tire) { case 7: // try a let let vTemp = Math.random(); console.log(vTemp); break; default: break; } } function onInit() { setInterval(test,1000); }
is it an error?
regards
-
hello @Gordon,
i have no predefined solution to switch on led on the matrix.
i just want to solve my prob who is that i have a graphic arrayBuffer with a font drawing and want to HIGH or LOW the pin of the espruino to display the content of the buffer on the matrix.
As i see in the datasheet of the matrix, it seems easier to pilot the display by line. but i haven't a good enough tech background to be sure of that. Your (@Gordon and @allObjects) attempts to explain are futile since I do not know how to switch from an arrayBuffer to a properly lit matrix with some digitalWrite()I ask you to forgive my gross ignorance. Shame on me.
All seems so simple for you!
not for me.
can iDigitalWrite(*array of pins*, *array of value like the b[i].toString(2)*)
?// pin of the matrix wired on the espruino const x= [A6,A5,A8,B7,B6]; const y=[B5,B4,B3,A7,B1,B10,B13]; //to ground???? let g = Graphics.createArrayBuffer(8,7,1); var b = new Uint8Array(g.buffer); for (let i=0; i<???;i++) { digitalWrite(???,???) }
-
-
well i do not understand the interest to display in col vs in row! except to have a smaller ArrayBuffer.
is it really faster?
how to read each bit of col?
I need to select each row and extract the bit from each byte stored in the buffer!!!
i should missed something in the process... i'm lostfor (let i=0; i<g.getWidth();i++) { console.log(b[i].toString(2)); // export a rotated display }
-
I think it should work.
// crée le buffer graphique 8x8 en 1 bit let g = Graphics.createArrayBuffer(5,7,8); let a = new Uint8Array(g.buffer); var compteur=0; var row= [A6,A5,A8,B7,B6]; var col=[B5,B4,B3,A7,B1,B10,B13]; function sendData() { g.clear(); g.setFont4x6(); g.setBgColor(1); g.setColor(0); g.drawString("HELLO",5-(compteur%30),0); for (let i=0; i<7*5; i+=5) { console.log(a[i],a[i+1],a[i+2],a[i+3],a[i+4]); } console.log(" ----------- "); for (let j=0; j<col.length;j++) { digitalWrite(col[j],0); for (let i=0; i<row.length;i++) { digitalWrite(row[i],a[(i*5)+i]);LED1.toggle(); } compteur++; digitalWrite(col[j],1); } } function onInit() { require("Font4x6").add(Graphics); for (let i=0; i<col.length;i++) { pinMode(col[i],"opendrain"); } for (let i=0; i<row.length;i++) { pinMode(row[i],"output"); } digitalWrite(B4,1); console.log("init affichage matrice 5x7 sans driver"); console.log("mém. used: "+Math.round(process.memory().usage/process.memory().total*100)+"%"); setInterval(sendData, 500); }
-
-
-
i've found them at sparkfun so time ago... they are from 1978's HP. but they are out of catalog
https://www.sparkfun.com/products/retired/12710 -
-
Hello Markus,
I do not have a pinned pico, i've used a pico board and pin header on breadboard without soldering anything (crap work!!!)
In an earlier version i was ligthting On dot by dot on the first line and it was working.
but it seems to light on the led but i'm not sure the out is a line...
with this one i'm a bit confuse how a graphic buffer and uint8Array work together!
if i drawString("H") in my arrayBuffer, it should look like this10001 //17 -> #11 10001 //17 -> #11 10001 //17 -> #11 11111 //31 -> #'1F' 10001 //17 -> #11 10001 //17 -> #11 10001 //17 -> #11
but the value from the graphicBuffer are not...
if i addfor (let i=0; i<a.length;i++) { console.log(a[i].toString(2)); }
my "brilliant" test :/
let g = Graphics.createArrayBuffer(5,7,1); let a = new Uint8Array(g.buffer); var compteur=0; var row= [A6,A5,A8,B7,B6]; // my 5 col function sendData() { g.clear(); g.drawString("H"); digitalWrite(B4,0); // select first row for (let i=0; i<row.length;i++) { digitalWrite(row[i],a[i]); } digitalWrite(B4,1); // leave First row compteur++; } function onInit() { require("Font4x6").add(Graphics); pinMode(B4,"opendrain"); for (let i=0; i<row.length;i++) { pinMode(row[i],"output"); } digitalWrite(B4,1); setInterval(sendData, 1000); }
é.
@allObjects,
Hello Markus, i've tried to add a diode N4007 to sda and scl... (as you explain) it's worse, it does not init.
The module have 2 10k resistor in pull-up on sda and scl.
is it possible to remove the resistors or change value to a 4k7?
i refer to an other post here
regards
é.