I am having trouble using the Serial port with TinyBasic.

Hi! I am making a pocket programmer like the one Ben Heck made, using an xbox 360 chatpad as a keyboard. I am using the TinyBasic implementation by Mike Field. My problem comes in attempting to send serial data to the chatpad while running TinyBasic. I am using an ATMEGA328P. (just on a breadboard) First of all, here is my code:

TinyBasic.cpp - Tiny Basic Code
Chatpad.cpp - Chatpad Drivers (I didn't rewrite the chip inside the Chatpad like Ben did. Just used the serial data already coming out of the chatpad.)

I am able to run pad.init in setup without any problems, but if I compile with pad.poll uncommented (in pollChatPad) nothing shows up on the lcd. I believe it is in a reset loop. Also, pad.init is supposed to send an "init message" to the chatpad, but when examined with a logic analyzer, nothing comes from the serial port. I know the chatpad works, because when I run it using this code, it works just fine, (using the same drivers) and characters show up just like they should. I dunno what is going wrong, hopefully one of you good people will know :slight_smile:

I realize this post is structured pretty crappy. Sorry bout that.

Can you attach the relevant code to a post please?

How to use this forum

I tried but it told me I went over the character limit.

Maximum attachment size allowed: 4096 KB, per post: 4

What? Your .cpp files, which fit into an Atmega328 are more than 4 Mb each? That's hard to believe. You must have a lot of comments.

Oh, alright, you wanted me to attach them. Sorry about that. I figured you wanted me to put the code in code blocks like you said under section 6 of this post. (Which, like I said, exceeds the character limit.)

TinyBasic.ino is the TinyBasic code.
test.ino is the code that the chatpad works fine with.
Chatpad.cpp and Chatpad.h are used in both sketches, and are the drivers for the chatpad.

TinyBasic.ino (26.1 KB)

Chatpad.cpp (7.6 KB)

Chatpad.h (3.99 KB)

test.ino (521 Bytes)

I think you've run out of memory. I added a Serial.println into setup (you can do that yourself, you know) to see if the "reset" message printed multiple times. eg.

void setup()
  Serial.begin (115200);
  Serial.println ();
  Serial.println ("Reset.");
  Serial.flush ();
  // set up the LCD's number of columns and rows: 
  lcd.begin(20, 4);
  chatPadUsed = false;
  pad.init(Serial, print_keys); 

It didn't even print once. So, that's a clue.

I copied your data declarations, and added memory debug code and tried to print available memory. No dice until I commented out this line:

static unsigned char memory[1400];

After that I got:


So you are therefore using 1463 + 1400 bytes (2863) out of a total of 2048. So, it crashes.

Debug code:

#include "memdebug.h"


void setup ()
  Serial.begin (115200);
  Serial.println ();

  Serial.println (getFreeMemory ());
  }  // end of setup

Wow! I lowered the memory array to 600 and it works just like it should now. Thanks so much! :slight_smile: I forgot to mention that I had tried to print things without success, too, by the way. Thanks again. Is it possible to add memory to the ATMEGA chips?

No, not really.

The Atmega2560 does have some sort of provision for extra RAM off the board, but I wouldn't get too excited.

Okay, thanks.