/* ********************************************************************* * pitone.cpp repeater PL Tone sine wave generator * * Copyright 2016-2017 by Larry Gauthier, K8UT * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * --------------------------------------------------------------------- * Requires C++ 2014 edition in compile statement * TO COMPILE: g++ -Wall -std=c++14 -o "%e" "%f" -l wiringPi * TO EXECUTE: sudo ./pitone * ********************************************************************* Derived from Raspberry Pi I2C interface demo by Byron Jacquot @ SparkFun Electronics> 4/2/2014 https://github.com/sparkfun/Pi_Wedge PREPARE YOUR PI FOR I2C OPERATION: Ensure you have the latest rev of everything. From the CLI: * sudo apt-get update * sudo apt-get upgrade * sudo rpi-update Turn on the I2C interface: * Pi >Preferencews >Rasperry Pi Configuration >Interfaces: enable I2C Increase I2C baudrate to 1200000: * From the CLI: sudo nano /boot/config.txt * Near the bottom of the file, find the entry for I2C. Should read "dtparam=i2c_arm=on" Add the following in a line immediately before that line "dtparam=i2c_baudrate=1200000" * Save the file and reboot * Get some tools for I2C operation: * From the CLI: sudo apt-get install -y i2c-tools Examine the I2C settings: * FILE DESCRIPTOR? From the CLI: i2cdetect -y 1 ** default descriptor is 60. Mine showed up as 62. (?) * BAUDRATE? From the CLI: dmesg | grep i2c Copy the Pi Tone program to your Pi * Probably easiest to transfer using WinSCP * Set excutable attributes from WinSCP, OR * Make executable from the CLI with: sudo chmod +x pitone Run the program with: * ./pitone * Watch the MCP4725 output with a scope or voltmeter * Stop with ctrl+C Auto-start and Improve stability of the timing using the linix CHRT commane * in the /etc/rc.local startup file: sudo nano /etc/rc.local * add the line: chrt - -99 ./pitone 110.9 32 The I2C API is documented here: https://projects.drogon.net/raspberry-pi/wiringpi/i2c-library/ The init call returns a standard file descriptor. More detailed configuration of the interface can be performed using ioctl calls on that descriptor. See the wiringPi I2C implementation (wiringPi/wiringPiI2C.c) for some examples. Parameters configurable with ioctl are documented here: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/i2c/dev-interface ******************************************************************************/