0

So I have some simple code for an Arduino device that I am trying to run on a Raspberry Pi, and I'm having some issues.

Here is the code:

#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}
}

A couple of errors popped up when running it on my raspberry pi, such as:

    receiver.c:13:1: error: unknown type name 'byte'
 byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
 ^~~~
receiver.c:15:1: error: unknown type name 'byte'
 byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
 ^~~~
receiver.c: In function 'setup':
receiver.c:23:1: error: 'Serial' undeclared (first use in this function)
 Serial.begin(9600);

So basically "byte" and "Serial" aren't working. Anyone have any ideas what I could replace these by?

ajnauleau
  • 109
  • 1

1 Answers1

2

You may be able to build your Arduino code to run on a Raspberry Pi at https://create.arduino.cc/ but there are no guarantees.

To read a serial device and do something with your data on a Raspberry Pi you're going to get more success with a simple python program

#!/usr/bin/python

import serial, string, time, sys

output = " "
ser = serial.Serial('/dev/ttyUSB0', 115200, 8, 'N', 1, timeout=0)

while True:
  while output != "":
    output = ser.readline()
    temp = output.split()
    try:
      print temp[0]
    except:
      pass
  time.sleep(1)
Dougie
  • 5,381
  • 11
  • 22
  • 30