Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Random number generator interface error.

  1. #1

    Random number generator interface error.

    I am trying to build a random number generator. I have already built the hardware portion of the RNG. I am planning to use the Teensy 3.1 as the interface between the PC and the RNG. I am using the Arduino 1.6.5 code writing app with the Teensyduino 1.25 plugin. However, writing such simple interface code is not as easy as I thought. Since the forum requires the complete code and I am trying to correct my imperfect code, here is my initial attempt at writing the interface code. I am using pin 2 as a digital read for the serial output of the RNG.

    int RandomValue = 0;
    Serial.begin(115200);

    void setup() {
    // put your setup code here, to run once:
    pinMode(2,INPUT_PULLUP);
    }

    void loop() {
    // put your main code here, to run repeatedly:
    RandomValue = digitalRead(2);
    Serial.println(RandomValue);
    }

    Since I have never used a Teensy 3.1 before, I haven't written any sketches for it. Henceforth, when I attempted to verify/compile my interface code, this is the error I get.


    Arduino: 1.6.5 (Windows 10), TD: 1.25, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimized (overclock), US English"

    sketch_nov14a:2: error: 'Serial' does not name a type
    'Serial' does not name a type

    What have I done wrong? Please help me correct my error.

  2. #2
    Senior Member
    Join Date
    Dec 2013
    Posts
    265
    HI

    Code:
    int RandomValue = 0;
    //move to setup() Serial.begin(115200);
    
    void setup() {
    // put your setup code here, to run once:
    pinMode(2,INPUT_PULLUP);
    Serial.begin(115200);
    }
    
    void loop() {
    // put your main code here, to run repeatedly:
    RandomValue = digitalRead(2);
    Serial.println(RandomValue);
    }

  3. #3
    Okay, thank you for providing the corrected coding. The new sketch complied okay.
    I uploaded the new sketch to my Teensy 3.1 and the Arduino app says it uploaded successfully.
    Now, how do I get the sketch to run properly?

  4. #4
    I need to have my RNG to automatically start running the sketch in the Teensy 3.1 the instant it is connected to the USB port. I am also unable to get any kind of display of the output from my RNG.

  5. #5
    Senior Member
    Join Date
    Dec 2013
    Posts
    265
    Hi
    I am trying to build a random number generator. I have already built the hardware portion of the RNG.
    I am planning to use the Teensy 3.1 as the interface between the PC and the RNG.
    I wish I had more details about your built hardware portion of the RNG to give a more specific answer.

    Are you trying to capture some random generated frequency on digital pin?

    Perhaps you should try FreqMeasure Library or FreqCount Library.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •