Code Monkey home page Code Monkey logo

arduino-to-csv-api's Introduction

Arduino To CSV API

Save csv files with sensor data on you computer, no shields or additional devices needed

(pls let me know any problem, i barely know what im doing lol ๐Ÿ˜ฌ)

  • Serial comm-based Python script and Arduino code.
  • Automate data collection over Serial Ports, provide your own config and timing
  • Change timestamp format, prefix, sufix, timed or enumerated output in the config.json file. Alternatively provide your own JSON file as:
$ python3 main.py yourfile.json

Your file must follow this format:

{
    "filesPath": null,
    "prefix": "Example",
    "sufix": "Example",
    "timestampF": "%B %d %H:%M:%S",
    "baudRate": null,
    "port": null,
    "ignorePorts":null
}
  • filespath: Absolute path to save output csvs, leave at null for local repo saving on /CSVs/
  • prefix: string prefix on filename
  • sufix: string sufix on filename
  • timestampF: format string for the timestamp on the filename see datetime documentation or https://strftime.org
  • baudRate: bR of connection, default is 9600
  • port: String of known port, if null autoconnect is enabled
  • ignorePorts: Array of ports to be ignored at autoConnect

Pyserial is need to run, install as follows

$ pip install pyserial

Setup:

  1. Upload yoursketch.ino to your board
  2. Keep your board connected to your computer
  3. Run main.py wait for the scrip to detect the arduino and connect to it.
  4. Trigger data transmission. A csv file will be saved with you data. See previous to change save path and filenames.

API Objects

Serial logger

New logger

yourlogger = SerialLogger(baud=9600,parity="N",stopbits=1,verbose=True)

Autoconnect

yourlogger.autoConnect(port_list=serial.tools.list_ports.comports(),word=None,rest=True,ignorelist=None)
  • port_list: List of ports to be scanned, default is pyserial comports()
  • word: Word to be looked for in port name
  • rest: If "word" is not found try rest of ports
  • ignorelist: List of ports to be ignored

Manual connect

yourlogger.connector(port,tries=2)
  • tries: Connection tries

Both connectors return a pyserial serial connection object

yourconnector.MultipleReader(connection)
  • connection: Serial connection object

Returns data array. Serial line in each item

CSV writer

yourWriter = csvwriter(prefix=None,sufix=None,here=False,timeStamp=True,format=None,path=None)
  • prefix: Prefix for files
  • sufix: Sufix for files
  • here: Write files in current directory
  • timeStamp: Write timestamp condition
  • format: Timestamp format, see https://strftime.org
  • path:Path for file writing

Make name

name = yourWriter.makeName()

Returns generated name string

Write to file

yourWriter.csvWrite(name,data,mode="w"):
  • name: Name to save file as, (eg =.makeName() )
  • data: Data array to be written (eg =SerialLogger.MultipleReader() )
  • mode: 'w': Write, 'a': Append

Outputs a .csv file

Example

Run main.py

$ python3 main.py your-own-config.json

Script will connect to configured ports, read values and write the in a loop

    ...

logger = SerialLogger()
connection = logger.autoConnect(ignorelist=ignorePorts)

while True:
    data = logger.MultipleReader(connection)
    writer = csvwriter(prefix=prefix,sufix=sufix,here=False,timeStamp=True,format=timestampF,path=filesPath)
    name = writer.makeName()
    writer.csvWrite(name,data)

...   

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.