Question

In: Computer Science

Create a code showing Arduino IMU data being plotted by your Python code.  

Create a code showing Arduino IMU data being plotted by your Python code.  

Solutions

Expert Solution

>>Answer

>>Given That

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

#include "Wire.h"    // imports the wire library for talking over I2C

#include "Adafruit_BMP085.h"  // import the Pressure Sensor Library

Adafruit_BMP085 mySensor;  // create sensor object called mySensor

float tempC;  // Variable for holding temp in C

float tempF;  // Variable for holding temp in F

float pressure; //Variable for holding pressure reading

void setup(){

Serial.begin(115200); //turn on serial monitor

mySensor.begin();   //initialize mySensor

}

void loop() {

tempC = mySensor.readTemperature(); //  Be sure to declare your variables

tempF = tempC*1.8 + 32.; // Convert degrees C to F

pressure=mySensor.readPressure(); //Read Pressure

Serial.print(tempF);

Serial.print(" , ");

Serial.println(pressure);

delay(250); //Pause between readings.

}

import serial # import Serial Library

import numpy  # Import numpy

import matplotlib.pyplot as plt #import matplotlib library

from drawnow import *

tempF= []

pressure=[]

arduinoData = serial.Serial('com11', 115200) #Creating our serial object named arduinoData

plt.ion() #Tell matplotlib you want interactive mode to plot live data

cnt=0

def makeFig(): #Create a function that makes our desired plot

    plt.ylim(80,90)                                 #Set y min and max values

    plt.title('My Live Streaming Sensor Data')      #Plot the title

    plt.grid(True)                                  #Turn the grid on

    plt.ylabel('Temp F')                            #Set ylabels

    plt.plot(tempF, 'ro-', label='Degrees F')       #plot the temperature

    plt.legend(loc='upper left')                    #plot the legend

    plt2=plt.twinx()                                #Create a second y axis

    plt.ylim(93450,93525)                           #Set limits of second y axis- adjust to readings you are getting

    plt2.plot(pressure, 'b^-', label='Pressure (Pa)') #plot pressure data

    plt2.set_ylabel('Pressrue (Pa)')                    #label second y axis

    plt2.ticklabel_format(useOffset=False)           #Force matplotlib to NOT autoscale y axis

    plt2.legend(loc='upper right')                  #plot the legend

    

while True: # While loop that loops forever

    while (arduinoData.inWaiting()==0): #Wait here until there is data

        pass #do nothing

    arduinoString = arduinoData.readline() #read the line of text from the serial port

    dataArray = arduinoString.split(',')   #Split it into an array called dataArray

    temp = float( dataArray[0])            #Convert first element to floating number and put in temp

    P =    float( dataArray[1])            #Convert second element to floating number and put in P

    tempF.append(temp)                     #Build our tempF array by appending temp readings

    pressure.append(P)                     #Building our pressure array by appending P readings

    drawnow(makeFig)                       #Call drawnow to update our live graph

    plt.pause(.000001)                     #Pause Briefly. Important to keep drawnow from crashing

    cnt=cnt+1

    if(cnt>50):                            #If you have 50 or more points, delete the first one from the array

        tempF.pop(0)                       #This allows us to just see the last 50 data points

        pressure.pop(0)


Related Solutions

Create a code where you click on the appropriate buttons on your Python GUI and it...
Create a code where you click on the appropriate buttons on your Python GUI and it turns on and off the corresponding LEDs for Arduino, please.
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following...
THIS IS FOR ARDUINO PROGRAMMING Write code that checks the sensor data and meets the following conditions: For night conditions, turn on white LED 1 For day conditions, turn off white LED 1 Code should check intervals every 5 seconds. NEED THE BELOW CODE TO FIT THE ABOVE REQUIREMENTS. const int lightSensor = 5; //light sensor variable float sensValue = 0; //variable to hold sensor readings const int button = 3; //pin for button reads const int LED1 = 5;...
Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
This is using Python, it is utilizing code from a Fraction class to create a Binary...
This is using Python, it is utilizing code from a Fraction class to create a Binary Class Please leave comments so I may be able to learn from this. Instruction for Binary Class: Exercise 6.18: Design an immutable class BinaryNumber, in the style of our Fraction class. Internally, your only instance variable should be a text string that represents the binary value, of the form '1110100'. Implement a constructor that takes a string parameter that specifies the original binary value....
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
Power Factor Code Arduino Develop a Power factor Program in C and upload it into your...
Power Factor Code Arduino Develop a Power factor Program in C and upload it into your Arduino #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Python 3 Calendar does not showing up Fix code: # required library import tkinter as tk...
Python 3 Calendar does not showing up Fix code: # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money = tk.Entry(window) # arraging barcode.grid(row=0, column=1) product.grid(row=1, column=1) money.grid(row=2, column=1) cal = DateEntry(window, width=12, year=2019,...
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT