"Serial was not declared in this scope" and other ATtiny85 problem

char foo;

#include <SoftwareSerial.h>
int fsrReading;
#include "Servo8Bit.h"
Servo8Bit my;
const int buttonPin = 0;
const int pos = 20;

int buttonstate = 0;
 
void setup(void) {
 Serial.begin(9600);
  my.attach(1);
  my.write(180);
  delay(1);
  my.write(0);
  delay(1);
  my.write(180);
  pinMode(buttonPin, INPUT);
}
 
void loop(void) {
  fsrReading = analogRead(A1);


  buttonstate = digitalRead(buttonPin);
  
 
  if (fsrReading > 290) {
    my.write(0);
    
  
  } else{
    if (buttonstate == HIGH) {
      my.write(180);
      
    
 
  }
 }
}

When I try to verify the code, it says that serial was not declared in the scope…
I know it has been brought up before, but everything I try doesn’t seem to work.
I am using an attiny85 chip.
Also, while I’m making this I might as well include my other problem.
I have the sweep code on my chip, but when I try to upload a new program onto the chip, it still uses the sweep code. The IDE shows that it uploaded, but the sweep code still seems to be on the chip.
Any help is greatly appreciated.

The # statements need to go before ALL other code.

Why do you have this? You don’t seem to be using it.
#include <SoftwareSerial.h>

CrossRoads:
The # statements need to go before ALL other code.

Why do you have this? You don’t seem to be using it.
#include <SoftwareSerial.h>

#include <Servo8Bit.h>
int fsrReading;

Servo8Bit my;
const int buttonPin = 0;
const int pos = 20;

int buttonstate = 0;

Like this?
I tried it, but I still get the same error.

#include <SoftwareSerial.h>

and

Serial.begin(9600);

Aren’t talking about the same thing.

The latter does not exist on the Tiny85.

Ah - ATtiny85 has a serial interface, but not a UART:

  1. USI – Universal Serial Interface 15.1 Features • Two-wire Synchronous Data Transfer (Master or Slave) • Three-wire Synchronous Data Transfer (Master or Slave) • Data Received Interrupt • Wakeup from Idle Mode • Wake-up from All Sleep Modes In Two-wire Mode • Two-wire Start Condition Detector with Interrupt Capability

So SoftwareSerial is used instead. So instead of Serial.begin(9600) you need to call the SoftwareSerial equivalent.

Small correction...

Delta_G: The latter [u]does[/u] not exist on the Tiny85.

http://forum.arduino.cc/index.php?topic=51984.msg370691#msg370691

Example using TinyDebugSerial and Coding Badly’s core
Output on pin PB3

void setup() {
Serial.begin(9600);
}

void loop() {
  Serial.println("Testing..");
}

Example using SoftwareSerial

#include <SoftwareSerial.h>
const int rx=3;
const int tx=4;

SoftwareSerial mySerial(rx,tx);

void setup() 
{ 
mySerial.begin(9600);
} 

void loop() {
  if (mySerial.available()) {
    char data = mySerial.read();
    mySerial.write(data);
  }
}

Example using TinyDebugKnockBang

#include <TinyDebugKnockBang.h>

void setup( )
{
Debug.begin( 250000 );
}

void loop( )
{
Debug.println("Test knock-bang");
delay( 1000 );
}
#include <SoftwareSerial.h>
const int rx=3;
const int tx=4;

SoftwareSerial mySerial(rx,tx);

void setup() 
{ 
mySerial.begin(9600);
} 

void loop() {
  if (mySerial.available()) {
    char data = mySerial.read();
    mySerial.write(data);
  }
}

When I inserted parts of this into my code, everything uploads now, but it still has the sweep program stuck on it. The IDE says that it uploaded, but when I plug it into my circuit, it still runs the sweep code. Any tips there?

Post the verbose output from an upload attempt.

When I inserted parts of this into my code, everything uploads now, but it still has the sweep program stuck on it. The IDE says that it uploaded, but when I plug it into my circuit, it still runs the sweep code. Any tips there?

POST YOUR CODE!

#include <SoftwareSerial.h>

#include <Servo8Bit.h>
const int rx=3;
const int tx=4;

SoftwareSerial mySerial (rx , tx);

int fsrReading;

Servo8Bit my;
const int buttonPin = 0;
const int pos = 20;
int led = 0;
int buttonstate = 0;
 
void setup(void) {
mySerial.begin(9600);
 digitalWrite(led, HIGH);
 digitalWrite(led, LOW);
  my.attach(1);
  my.write(180);
  delay(1);
  my.write(0);
  delay(1);
  my.write(180);
  pinMode(buttonPin, INPUT);
}
 
void loop(void) {
  fsrReading = analogRead(A1);


  buttonstate = digitalRead(buttonPin);
  
 
  if (fsrReading > 290) {
    my.write(0);
    
  
  } else{
    if (buttonstate == HIGH) {
      my.write(180);
      
    
 
  }
 }
}

I don’t think the ‘sticky program’ has anything to do with the code, but I’ll run some tests tomorrow.

Post the verbose output from an upload attempt.

What do you mean by this?

File/Preferences/Show verbose output during:. Check both compilation and upload. You will get more information in the bottom window of the IDE when compiling and uploading. Post a copy of that here.

Are you uploading this or this?

UKHeliBob: File/Preferences/Show verbose output during:. Check both compilation and upload. You will get more information in the bottom window of the IDE when compiling and uploading. Post a copy of that here.

I can't seem to copy it. I cannot right click the highlighted piece to copy it.

Are you uploading this or this?

The second one.

Left click anywhere in the window, Ctrl/A to select all the text then Ctrl/C to copy it.

From reply #7 which included very non-"sweepy" code...

WireJunky: When I inserted parts of this into my code, everything uploads now, but it still has the sweep program stuck on it. The IDE says that it uploaded, but when I plug it into my circuit, it still runs the sweep code. Any tips there?

In reply #13 you said you are uploading a sketch that looks very "sweepy" to me.

What are you uploading and what do you expect to happen when you upload it?

#include <SoftwareSerial.h>

#include <Servo8Bit.h>
const int rx=3;
const int tx=4;

SoftwareSerial mySerial (rx , tx);

int fsrReading;

Servo8Bit my;
const int buttonPin = 0;
const int pos = 20;
int led = 0;
int buttonstate = 0;
 
void setup(void) {
mySerial.begin(9600);
 digitalWrite(led, HIGH);
 digitalWrite(led, LOW);
  my.attach(1);
  my.write(180);

  pinMode(buttonPin, INPUT);
}
 
void loop(void) {
  fsrReading = analogRead(A1);


  buttonstate = digitalRead(buttonPin);
  
 
  if (fsrReading > 290) {
    my.write(0);
    
  
  } else{
    if (buttonstate == HIGH) {
      my.write(180);
      
    
 
  }
 }
}

This is what i am uploading NOW.
This is what is supposed to happen:

  1. Turned on
  2. Servo goes to 180 degrees
  3. Program waits for force sensor to send a reading back
  4. if detected, servo goes to 0 degrees
  5. Program waits for button press
  6. If button is pressed, servo goes back to 180 degrees

None of this happens. I upload it onto the chip, I place it in my circuit, I turn on the power, and it runs the sweep code.

int led = 0 ;
int buttonstate = 0 ;

digitalWrite(led, HIGH);
digitalWrite(led, LOW);

pinMode(buttonPin, INPUT);

The pushbutton is connected to which pin?

The LED is connected to which pin?

I must’ve forgotten to take out the led part, I added that when I was testing if the chip still had the sweep program on it.

float average (float A, float B, float C){ float result = (A+B+C)/3; return result; }

void setup(){ serial.begin(9600); float avg = serial.print(avg); }

void loop(){ //put your main cod here, to run repeatedly: }