Buggy Library – Too Unstable to use for simplest of tasks.

Store Forums Video Experimenter Bugs/Problems Buggy Library – Too Unstable to use for simplest of tasks.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #767
    BradM
    Member

    I’ve been playing with the video experimenter, and have determined that it is unusable for even the simplest of applications. I tried to build a complex application, and got nowhere fast and gave up. I bought a second Arduino Uno to offload all the complicated stuff, so the Arduino running the Video Experimenter could work on that single task.

    I’m basically trying to build a chunk of code that will read a line of text from the serial port, and display it to the screen. I can’t get anywhere near that far with the code before the Arduino locks up and hangs.

    I’m trying to build a chunk of code that:
    1. Reads a string of text from the serial port.
    2. Strips off any leading * ‘s.
    3. If the first 2 characters are 01, clear the screen with tv.fill(0)
    4. If the first 2 characters are 02, grab the next 2 characters as the x coordinate, the next 2 as y, and the rest as the string to display, then use tv.print to display the string on the screen at the co-ordinates.

    Simple right? Nope, not possible. I’ve dumbed down the code, removed all loops, made it as simple as possible, trying to do as little as possible each time loop executes, and the code is unstable and unpredictable.

    I’m including a chunck of code, this code actually compiles and runs. The first string sent in is usually interpreted as random garbage, not matching what was sent. The second and 3rd strings usually process correctly, and the 4th and 5th strings will completely hang the arduino. I’ve never been able to input anything past 5 strings before the device hangs.

    I have code at the end to blink the LED, this is so I can tell if the Arduino loop is running, or if the device has locked up. There are also 2 sections at the end that are commented out, if they are uncommented, the Arduino locks up on boot, doesn’t even display the “Booting” message from the setup, and they are both simple if statements which the code will never get to initially.

    If anybody has any suggestions on how to build this very very very very SIMPLE piece of code, I’m interested, but after 3 days of trying hundreds of ways to write this simple bit of code, I’m all but giving up and determining this product to be useless junk.

    #include
    #include #include

    #define W 136
    #define H 96

    #define ON 1
    #define OFF 0

    #define LED_PIN 13

    TVout tv;
    pollserial pserial;

    int readserial = 0;
    bool stat = false;
    bool debug = true;
    char buff[32];
    int len = 0;
    int i = 0;
    char cmd[3];

    void setup() {
    tv.begin(NTSC, W, H);
    initOverlay();
    tv.select_font(font6x8);
    tv.fill(0);
    tv.delay_frame(6);
    tv.print(0, 0, “Booting…”);
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);
    tv.set_hbi_hook(pserial.begin(19200));
    if (debug) {
    pserial.println(“Booting…”);
    }
    tv.delay(500);
    tv.fill(0);
    }

    void loop() {
    if (readserial == 0) {
    if (len = pserial.available()) {
    if (debug) {
    pserial.print(“Length: “);
    pserial.println(len);
    }
    readserial = 1;
    i = 0;
    }
    }

    if (readserial == 1) {
    buff = pserial.read();
    i++;
    if (i == len) {
    buff
    = 0;
    readserial = 2;
    i = 0;
    if (debug) {
    pserial.print(“String Received: “);
    pserial.println(buff);
    }
    }
    }

    if (readserial == 2) {
    if (buff
    == ‘*’) {
    i++;
    }
    else {
    readserial = 3;
    if (debug) {
    pserial.print(“Asterisks Detected: “);
    pserial.println(i);
    }
    }
    }

    if (readserial == 3) {
    cmd[0] = buff
    ;
    cmd[1] = buff[i+1];
    cmd[2] = 0;
    if (debug) {
    pserial.print(“Command #”);
    pserial.println(cmd);
    }
    /*
    if (strcmp(cmd, “00”) == 0) {
    if (debug) {
    pserial.println(“Command 0 detected: Doing Nothing”);
    }
    }
    */
    if (strcmp(cmd, “01”) == 0) {
    if (debug) {
    pserial.println(“Command 1 detected: Clearing Screen”);
    }
    pserial.println(“Screen Clear”);
    tv.fill(0);
    }
    /*
    else {
    if (debug) {
    pserial.println(“*** INVALID COMMAND ***”);
    }
    }
    */
    readserial = 0;
    }

    if (stat == false) {
    digitalWrite(LED_PIN, HIGH);
    tv.print(21*6, 11*8, “*”);
    stat = true;
    }
    else {
    digitalWrite(LED_PIN, LOW);
    tv.print(21*6, 11*8, ” “);
    stat = false;
    }
    tv.delay(50);
    }

    // Initialize ATMega registers for video overlay capability.
    // Must be called after tv.begin().
    void initOverlay() {
    TCCR1A = 0;
    // Enable timer1. ICES0 is set to 0 for falling edge detection on input capture pin.
    TCCR1B = _BV(CS10);

    // Enable input capture interrupt
    TIMSK1 |= _BV(ICIE1);

    // Enable external interrupt INT0 on pin 2 with falling edge.
    EIMSK = _BV(INT0);
    // Tried ISC01 as well, no change to symptoms
    EICRA = _BV(ISC11);
    }

    // Required to reset the scan line when the vertical sync occurs
    ISR(INT0_vect) {
    display.scanLine = 0;
    }

    #2255
    Michael
    Keymaster

    I’m all but giving up and determining this product to be useless junk

    Brad, I’m sorry you are having problems with your Arduino program, but saying things like this is not a very good way to get help. However, I’ll still try.

    Looking at your program, the first thing that jumps out at me is that you are using a lot of SRAM. When you use too much memory, Arduino programs tend to stop functioning or just go haywire. There are only 2K of SRAM in the ATmega328 microcontroller. The frame buffer used by TVout takes up a LOT of it. At the resolution you are trying to use (136×96) you are consuming 1632 bytes just for the frame buffer. Perhaps you can try lowering this to 128×96 which is the default TVout resolution.

    Your code has a lot of long string literals, like “Command 1 detected: Clearing Screen” and “Command 0 detected: Doing Nothing”. Each one of these consumes SRAM. By my count, you have 183 bytes of string literals in your program, so adding this to the frame buffer, you are using 1815 bytes of the 2K. That does not leave much memory for much else. I think you are just running out of memory. Declaring string literals as flash memory will reduce your SRAM usage. See http://www.arduino.cc/en/Reference/PROGMEM for some guidance.

    I hope you can solve the problems with your program. Hundreds of people use the Video Experimenter for useful projects and even industrial applications. It is admittedly primitive and simple (and VERY inexpensive), but I don’t think it is “useless junk”.

    #2256
    BradM
    Member

    I may have been harsh with my comment, but after 3 days of fighting with it, reading forum messages for suggestions, re-writing the program, re-re-writing the program, re-re-re-re-writing the program…

    I was beyond frustrated when I posted that. The most frustrating thing was the lack of any clue as to what was going on. It’s difficult to debug when things just lock up and you don’t get any debug output of any kind.

    If you think I’m just running out of memory, that’s easy enough to work around. Most of the string literals were for debugging purposes anyway, they aren’t required for the final project, so they can go. I was under the assumption I was using too much CPU as every message I read pointed in that direction. There was no mention of running out of memory. When I compile the program it says I’m using 251 bytes of memory (12%), no indication of running out.

    I’ll play with it, if it’s a memory problem, that will be easy enough to prove. I’ll let you know how it goes.

    #2257
    Michael
    Keymaster

    When you compile and it says you are using 12%, that is how much of the 32K of flash memory you are using to store your program. Your problem is with SRAM that the program uses while running. You are using almost all of it, so there is no more room for the stack. You are almost certainly overflowing the stack.

    #2258
    BradM
    Member

    I’m looking at the code now, so I’ll see what I can do with it.

    When I compile the code above, I get:

    Sketch uses 10,690 bytes (33%) of program storage space. Maximum is 32,256 bytes.
    Global variables use 251 bytes (12%) of dynamic memory, leaving 1,797 bytes for local variables. Maximum is 2,048 bytes.

    It was the last line I was looking at , hence not realizing something else was burning all the memory.

    #2259
    Michael
    Keymaster

    The frame buffer alone is going to use up 1,632 bytes of the 1,797 bytes. That leaves very little for your stack.

    #2290
    BradM
    Member

    Sorry for the long delay in replying. Using less memory definitely solved the problem. I had to get very creative with the coding, but I got it to work.

    Thanks.
    Brad.

    #2291
    Michael
    Keymaster

    That’s great to hear. Embedded programming is much more challenging than writing software on a computer that has enormous resources. Working in a constrained environment is what brings out creativity and cleverness. It will make you a better coder.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.