TinyCircuits Forum
TinyCircuits Products => Tiny Arcade & Pocket Arcade => Topic started by: gef3233 on January 03, 2017, 10:46:44 AM
-
Hello all,
I am programming the TinyArcade, using Ubuntu.
I have a basic modification of TinyScreenBasicExample.ino:
void setup(void) {
Wire.begin();//initialize I2C before we can initialize TinyScreen- not needed for TinyScreen+
display.begin();
//setBrightness(brightness);//sets main current level, valid levels are 0-15
display.setBrightness(10);
Serial.begin(9600);
}
void loop() {
Serial.print("hello!");
}
My problem is that after uploading the sketch, the TinyArcade disconnects from the serial port and I am unable to send/receive any data.
Also, I might be uploading the sketch incorrectly, the only way I found my code to run (still without the serial part) was uploading the code as "TinyArcade Menu", the "Binary for SD card" option does not seem to work.
Can somebody help me with those issues? How should I create the binary to upload it to the SD card like the example games are?
Thanks!
-
Ok, I could finally figure it out. Apparently I had to use a serial USB. I attach the code with an example so everyone that needs it can benefit from it:
//-------------------------------------------------------------------------------
//
// This example should help new users to communicate to their tinyarcades via serial port
//
// Written by Pablo Jimenez Mateo
//-------------------------------------------------------------------------------
#include <Wire.h>
#include <TinyScreen.h>
TinyScreen display = TinyScreen(TinyScreenPlus);
void setup(void) {
Wire.begin();//initialize I2C before we can initialize TinyScreen- not needed for TinyScreen+
display.begin();
display.setBrightness(10);
//This is for serial communication
USBDevice.init();
USBDevice.attach();
SerialUSB.begin(9600);
}
void loop() {
delay(1500);
SerialUSB.println("Hi");
String cmd = "";
//Read an entire line from serial
while (SerialUSB.available() > 0) {
cmd += (char)SerialUSB.read();
}
if (cmd.length() > 2) {
writeText(cmd);
} else {
writeText("No text :(");
}
}
void writeText(String text){
//String to char*
char t[text.length()+1];
text.toCharArray(t, text.length() + 1);
display.clearScreen();
//setFont sets a font info header from font.h
//information for generating new fonts is included in font.h
display.setFont(thinPixel7_10ptFontInfo);
int width = display.getPrintWidth(t);
//setCursor(x,y);//set text cursor position to (x,y)- in this example, the example string is centered
display.setCursor(48-(width/2),20);
//fontColor(text color, background color);//sets text and background color
display.fontColor(TS_8b_Green,TS_8b_Black);
display.print(t);
}
-
THANK YOU!