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?

asked Jan 23, 2020 at 22:48
2
  • 1
    Does this answer your question? Use Arduino code on raspberry pi? Commented Jan 23, 2020 at 22:56
  • 1
    You are going to have many problems. A Pi is not an Arduino. Commented Jan 23, 2020 at 23:14

1 Answer 1

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)
answered Jan 24, 2020 at 0:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.