White screen?

edited February 2014 in Arduino

I've had a little trouble with the sketch I wrote up in order to autoselect the port that my Arduino was on.

Arduino code: http://pastebin.com/4G7cNH4a

Processing code: http://pastebin.com/t12hmgq3

I wrote this applet for Windows, as I have never used OSX productively, and it is purely for personal use.

My Arduino repeatedly sends a char over Serial port COM4 (on USB). I told processing to set a serial object to Serial.list()[1], which should mean that the loop I wrote for selecting the port skips over index[0] in Serial.list(). This is intentional; external devices never connect to COM1 over USB, as far as I know.

In the looping function I wrote, portSelect(), what it's doing is checking to see whether there's any data available to read. Then, if there is, it checks to see if it's confChar. If it's not, it changes the value of the Serial object commsPort by setting it equal to Serial.list()[avIndex] directly after adding 1 to avIndex in the For loop.

I don't know what's going on, but I do know that none of the other applets I've written so far are doing this white screen thing. I'm completely stumped here; everything looks correct.

Also, first time on the forums :) I hope you guys have some nice feedback. Layman's explanations please, I'm relatively new to coding in general.

Answers

  • edited February 2014 Answer ✓

    hi there,

    it might be that you have the white screen, because your code failed somehow before you could finish your first draw. to be honest your portSelect() looks somehow overly complicated. i tried to make sense of your creative for loops, but i couldn't figure it out completly.

    here is a version how i would do it. i tried to comment everything thats important. just ask if you have any questions. since i don't have serialports active on my mac i couldn't test it fully. but i think it should work.

    import processing.serial.*;
    
    PFont Consolas;
    String systMessage="";
    char confChar=7;
    Serial commsPort;
    int avIndex=0;
    int indent=25;
    int largeIndent=120;
    int scanDelay=690;
    int time=millis();
    int wait=690;
    boolean selectionComplete=false;
    boolean displayDefaultScanMsg=true;
    
    void setup()
    {
      size(800, 600);
      Consolas=createFont("Consolas", 17, true);
      background(0);
    }
    
    void draw()
    {
      background(0);
      portSelect();
      text(systMessage+(frameCount/10%2==0?"_":""), largeIndent, 60);
      if(selectionComplete){
          // do stuff with commPort here
      }
    }
    
    void portSelect()
    {
      if (selectionComplete == false) {
        if (Serial.list().length > 0) {
          if (millis()-time >= wait) {
            time=millis();
            commsPort=new Serial(this, Serial.list()[avIndex], 38400);
            if (commsPort != null) {
              // commsPort not null yeah!
              if (commsPort.available() > 0) {
                // commsPort has bytes to read 
                if (commsPort.read()==confChar) {
                  // commsPort sends confChar yeah!
                  commsPort.write(confChar);
                  selectionComplete=true;
                }
                else {       // not the confChar
                  avIndex++; // try next one
                }
              } 
              else {       // no bytes available 
                avIndex++; // try next one
              }
            }
            else {    // commport is null
              println("Oops, serial port is null at index "+avIndex);
              text("Oops, serial port is null at index "+avIndex, largeIndent, 40);
              avIndex++;  // try next one
            }
            if (avIndex >= Serial.list().length) { // if avIndex > number of serial ports
              avIndex = 0; // set it to 0
            }
          }
        }
        else {
          println("Oops, no serial port found");
          text("Oops, no serial port found", largeIndent, 40);
        }
      }
    }
    
  • edited February 2014

    Thanks! No, no questions - the program does at least run now. However, you tweaked the avIndex to zero by default, meaning that the program begins scans at Serial.list()[0], which is somewhat purposeless - I know the Arduino is not connected there because it is not mounted on the nine-pin serial port via the motherboard. This does make it a more universal program, however, so thanks for that, I suppose.

    It is instead wired to a virtual Serial port being emulated by USB, so I won't be COM1. This trips up the program just a bit. Thanks for writing such heavy revisions, though - it's greatly appreciated! I did run it, and while it experiences similar errors to earlier revisions (before whiteScreens began occurring), it does at least draw properly. Thanks again!

  • Beware of the term "applet", in general, at least in the Java world, it means "a Java program running in a browser". For small Processing programs, we prefer the term "sketch".

    Also there is a forum section for Arduino, I moved your post there.

Sign In or Register to comment.