Switching from Uno to Trinket: Problems utilizing Serial & Serial.println

Hi folks,

I had this project working on an arudino uno, based on the circuit found here .

Here is my original code, designed to make the LED blink when the FSR registers a force over a certain threshold.

int pressurePin = A0;
int force;
int LEDpin = 12;
void setup() {
Serial.begin(9600);
pinMode(LEDpin, OUTPUT);
}
void loop() {
  force = analogRead(pressurePin);
  Serial.println(force);
if(force > 950){
      // turn LED on:
     digitalWrite(LEDpin, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);               // wait for a second
      digitalWrite(LEDpin, LOW);    // turn the LED off by making the voltage LOW
       delay(1000);               // wait for a second
  } else {
    // turn LED off:
    digitalWrite(LEDpin, LOW);
  }
}

Now with the 5V trinket I have the same circuit, but I realize there is no serial port, so I am trying to figure out how to get the same effect of the LED blink loop once the FSR registers a certain pressure, and then turn off the LED when the pressure is released.

I am using USBTinyISP for the programmer.

Here is my current code, and the pinout of the 5V Trinket: Pinouts | Introducing Trinket | Adafruit Learning System

int pressurePin = 2;
int force;
int LEDpin = 1;
void setup() {
  Serial.begin(9600);
pinMode(LEDpin, OUTPUT);
}
void loop() {
  force = analogRead(pressurePin);
 Serial.println(F(force));
if(force > 950){
  // check if force is greater than 950
  // if it is
    // turn LED on:
     digitalWrite(LEDpin, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);               // wait for a second
      digitalWrite(LEDpin, LOW);    // turn the LED off by making the voltage LOW
       delay(1000);               // wait for a second
  } else {
    // turn LED off:
    digitalWrite(LEDpin, LOW);
  }
}

Which gives me the error 'Serial' was not declared in this scope

Am I missing a library that enables something similar? My googling and searching of this forum showed that there is not inherent serial port, but it sounds like something along those lines exists.

Thanks in advance!

(deleted)

The Serial code in that sketch is only used to print the analog read of the FSR. It sounds like you only care about the LED output. If so, you can just delete the two lines in the code that start with Serial.

Thanks, pert. I tried that originally, but to no avail. Perhaps it has to do with the analogRead function and having no true analog input available on the Trinket?

I’ve tried to set up SoftwareSerial, but I’m still experiencing issues. Do I need connections to both tx & rx pins? All I want to do is read the rxPin value and use that to define my if else loop.

#include <SoftwareSerial.h>
#define rxPin 3 //This is connected to a 10kOhm resistor, ground, and one end of FSR
#define txPin 4 //Currently disconnected

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

int force;
int LEDpin = 1;

void setup() {
   // define pin modes for tx, rx:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  pinMode(LEDpin, OUTPUT);
  }

void loop() {
  force = mySerial.read();
 mySerial.println(force);
if(force > 950){
  // check if force is greater than 950
  // if it is
    // turn LED on:
     digitalWrite(LEDpin, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);               // wait for a second
      digitalWrite(LEDpin, LOW);    // turn the LED off by making the voltage LOW
       delay(1000);               // wait for a second
  } else {
    // turn LED off:
    digitalWrite(LEDpin, LOW);
  }
}

I think you're getting very confused. You don't use SoftwareSerial to read an FSR. For that, the previous code's use of analogRead() was already correct. In addition to controlling the LED, the previous code also printed the value of force to Serial. That made is so you can open Serial Monitor and see the numbers, which is useful for debugging but not absolutely necessary if you only want to blink the LED.

(deleted)